Search in sources :

Example 1 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project intellij-community by JetBrains.

the class JUnit5TestRunnerUtil method buildRequest.

public static LauncherDiscoveryRequest buildRequest(String[] suiteClassNames, String[] packageNameRef) {
    if (suiteClassNames.length == 0) {
        return null;
    }
    LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request();
    if (suiteClassNames.length == 1 && suiteClassNames[0].charAt(0) == '@') {
        // all tests in the package specified
        try {
            BufferedReader reader = new BufferedReader(new FileReader(suiteClassNames[0].substring(1)));
            try {
                final String packageName = reader.readLine();
                if (packageName == null)
                    return null;
                String tagName = reader.readLine();
                String line;
                List<DiscoverySelector> selectors = new ArrayList<>();
                while ((line = reader.readLine()) != null) {
                    selectors.add(createSelector(line));
                }
                packageNameRef[0] = packageName.length() == 0 ? "<default package>" : packageName;
                builder = selectors.isEmpty() ? builder.selectors(DiscoverySelectors.selectPackage(packageName)) : builder.selectors(selectors);
                if (tagName != null && !tagName.isEmpty()) {
                    builder = builder.filters(TagFilter.includeTags(tagName));
                }
                return builder.build();
            } finally {
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        boolean disableDisabledCondition = isDisabledConditionDisabled(suiteClassNames[0]);
        if (disableDisabledCondition) {
            builder = builder.configurationParameter("junit.conditions.deactivate", "org.junit.*DisabledCondition");
        }
        return builder.selectors(createSelector(suiteClassNames[0])).build();
    }
    return null;
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) IOException(java.io.IOException) DiscoverySelector(org.junit.platform.engine.DiscoverySelector)

Example 2 with DiscoverySelector

use of org.junit.platform.engine.DiscoverySelector in project junit5 by junit-team.

the class JUnitPlatform method createDiscoveryRequest.

private LauncherDiscoveryRequest createDiscoveryRequest() {
    List<DiscoverySelector> selectors = getSelectorsFromAnnotations();
    // Allows to simply add @RunWith(JUnitPlatform.class) to any test case
    boolean isSuite = !selectors.isEmpty();
    if (!isSuite) {
        selectors.add(selectClass(this.testClass));
    }
    LauncherDiscoveryRequestBuilder requestBuilder = request().selectors(selectors);
    addFiltersFromAnnotations(requestBuilder, isSuite);
    return requestBuilder.build();
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) DiscoverySelector(org.junit.platform.engine.DiscoverySelector)

Example 3 with DiscoverySelector

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

the class DiscoverySelectorResolverTest method resolveRequestWithClasspathResourceSelectorAndFilePosition.

@Test
void resolveRequestWithClasspathResourceSelectorAndFilePosition() {
    String feature = "io/cucumber/junit/platform/engine/rule.feature";
    FilePosition line = FilePosition.from(5);
    DiscoverySelector resource = selectClasspathResource(feature, line);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(1L, testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).count());
}
Also used : FilePosition(org.junit.platform.engine.discovery.FilePosition) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with DiscoverySelector

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

the class DiscoverySelectorResolverTest method resolveRequestWithMultipleClasspathResourceSelector.

@Test
void resolveRequestWithMultipleClasspathResourceSelector() {
    DiscoverySelector resource1 = selectClasspathResource("io/cucumber/junit/platform/engine/single.feature");
    DiscoverySelector resource2 = selectClasspathResource("io/cucumber/junit/platform/engine/feature-with-outline.feature");
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource1, resource2);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(2, testDescriptor.getChildren().size());
}
Also used : DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 5 with DiscoverySelector

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

the class DiscoverySelectorResolverTest method resolveRequestWithUniqueIdSelectorFromFileUri.

@Test
void resolveRequestWithUniqueIdSelectorFromFileUri() {
    DiscoverySelector resource = selectDirectory("src/test/resources/io/cucumber/junit/platform/engine");
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    Set<? extends TestDescriptor> descendants = testDescriptor.getDescendants();
    descendants.forEach(targetDescriptor -> {
        resetTestDescriptor();
        resolveRequestWithUniqueIdSelector(targetDescriptor.getUniqueId());
        assertEquals(1, testDescriptor.getChildren().size());
        assertThat(testDescriptor, allDescriptorsPrefixedBy(targetDescriptor.getUniqueId()));
    });
}
Also used : DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) 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