Search in sources :

Example 16 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project gradle by gradle.

the class JUnitPlatformTestClassProcessor method createLauncherDiscoveryRequest.

private LauncherDiscoveryRequest createLauncherDiscoveryRequest(List<Class<?>> testClasses) {
    List<DiscoverySelector> classSelectors = testClasses.stream().map(DiscoverySelectors::selectClass).collect(Collectors.toList());
    LauncherDiscoveryRequestBuilder requestBuilder = LauncherDiscoveryRequestBuilder.request().selectors(classSelectors);
    addTestNameFilters(requestBuilder);
    addEnginesFilter(requestBuilder);
    addTagsFilter(requestBuilder);
    return requestBuilder.build();
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) DiscoverySelector(org.junit.platform.engine.DiscoverySelector)

Example 17 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithUriSelectorWithExampleLine.

@Test
void resolveRequestWithUriSelectorWithExampleLine() {
    File file = new File("src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature");
    URI uri1 = URI.create(file.toURI() + "?line=20");
    DiscoverySelector resource = selectUri(uri1);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    List<? extends TestDescriptor> tests = testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).collect(Collectors.toList());
    assertEquals(1, tests.size());
}
Also used : File(java.io.File) DiscoverySelectors.selectFile(org.junit.platform.engine.discovery.DiscoverySelectors.selectFile) URI(java.net.URI) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 18 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithPackageSelector.

@Test
void resolveRequestWithPackageSelector() {
    DiscoverySelector resource = selectPackage("io.cucumber.junit.platform.engine");
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(5, testDescriptor.getChildren().size());
}
Also used : DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 19 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithClasspathRootSelector.

@Test
void resolveRequestWithClasspathRootSelector() {
    Path classpathRoot = Paths.get("src/test/resources/");
    DiscoverySelector resource = selectClasspathRoots(singleton(classpathRoot)).get(0);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(6, testDescriptor.getChildren().size());
}
Also used : Path(java.nio.file.Path) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 20 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveFeatureTestDescriptorsInUriOrder.

@Test
void resolveFeatureTestDescriptorsInUriOrder() {
    Path classpathRoot = Paths.get("src/test/resources/");
    DiscoverySelector resource = selectClasspathRoots(singleton(classpathRoot)).get(0);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    Set<? extends TestDescriptor> features = testDescriptor.getChildren();
    List<TestDescriptor> unsorted = new ArrayList<>(features);
    List<TestDescriptor> sorted = new ArrayList<>(features);
    // Sorts by URI
    sorted.sort(comparing(feature -> feature.getUniqueId().getSegments().get(1).getValue()));
    assertEquals(unsorted, sorted);
}
Also used : Path(java.nio.file.Path) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) DiscoverySelectors.selectClasspathRoots(org.junit.platform.engine.discovery.DiscoverySelectors.selectClasspathRoots) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) HashMap(java.util.HashMap) CustomTypeSafeMatcher(org.hamcrest.CustomTypeSafeMatcher) DiscoveryFilter(org.junit.platform.engine.DiscoveryFilter) LoggerFactory(io.cucumber.core.logging.LoggerFactory) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) LogRecordListener(io.cucumber.core.logging.LogRecordListener) HashSet(java.util.HashSet) FilePosition(org.junit.platform.engine.discovery.FilePosition) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) DiscoverySelectors.selectClasspathResource(org.junit.platform.engine.discovery.DiscoverySelectors.selectClasspathResource) URI(java.net.URI) Comparator.comparing(java.util.Comparator.comparing) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) NoFeatures(io.cucumber.junit.platform.engine.nofeatures.NoFeatures) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) DiscoverySelectors.selectDirectory(org.junit.platform.engine.discovery.DiscoverySelectors.selectDirectory) Set(java.util.Set) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Paths(java.nio.file.Paths) Matcher(org.hamcrest.Matcher) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DiscoverySelectors.selectUri(org.junit.platform.engine.discovery.DiscoverySelectors.selectUri) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) Collections(java.util.Collections) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) DiscoverySelectors.selectFile(org.junit.platform.engine.discovery.DiscoverySelectors.selectFile) ArrayList(java.util.ArrayList) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

DiscoverySelector (org.junit.platform.engine.DiscoverySelector)27 Test (org.junit.jupiter.api.Test)23 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)23 URI (java.net.URI)7 TestDescriptor (org.junit.platform.engine.TestDescriptor)6 File (java.io.File)5 DiscoverySelectors.selectFile (org.junit.platform.engine.discovery.DiscoverySelectors.selectFile)5 FilePosition (org.junit.platform.engine.discovery.FilePosition)5 ArrayList (java.util.ArrayList)3 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 LogRecord (java.util.logging.LogRecord)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors (org.junit.platform.engine.discovery.DiscoverySelectors)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)2 LogRecordListener (io.cucumber.core.logging.LogRecordListener)1 LoggerFactory (io.cucumber.core.logging.LoggerFactory)1 NoFeatures (io.cucumber.junit.platform.engine.nofeatures.NoFeatures)1 BufferedReader (java.io.BufferedReader)1