Search in sources :

Example 1 with LauncherDiscoveryRequestBuilder

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder 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 LauncherDiscoveryRequestBuilder

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project junit5 by junit-team.

the class DiscoveryRequestCreator method toDiscoveryRequest.

LauncherDiscoveryRequest toDiscoveryRequest(CommandLineOptions options) {
    LauncherDiscoveryRequestBuilder requestBuilder = request();
    requestBuilder.selectors(createDiscoverySelectors(options));
    addFilters(requestBuilder, options);
    requestBuilder.configurationParameters(options.getConfigurationParameters());
    return requestBuilder.build();
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)

Example 3 with LauncherDiscoveryRequestBuilder

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder 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 4 with LauncherDiscoveryRequestBuilder

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method executesIncludedTaggedMethodOfNestedTestClass.

@Test
void executesIncludedTaggedMethodOfNestedTestClass() {
    Class<?> testClass = EnclosedJUnit4TestCase.class;
    Class<?> nestedTestClass = EnclosedJUnit4TestCase.NestedClass.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(includeTags(Categories.Failing.class.getName()));
    TestPlan testPlan = discover(request);
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(3);
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", testClass.getName(), nestedTestClass.getName(), "failingTest");
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Categories(org.junit.vintage.engine.samples.junit4.Categories) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 5 with LauncherDiscoveryRequestBuilder

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method removesWholeSubtree.

@Test
void removesWholeSubtree() {
    Class<?> testClass = EnclosedJUnit4TestCase.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(excludeTags(Categories.Plain.class.getName()));
    TestPlan testPlan = discover(request);
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).isEmpty();
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage");
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Categories(org.junit.vintage.engine.samples.junit4.Categories) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Aggregations

LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)16 Test (org.junit.jupiter.api.Test)11 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)11 TestIdentifier (org.junit.platform.launcher.TestIdentifier)11 TestPlan (org.junit.platform.launcher.TestPlan)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 JUnit4SuiteWithTwoTestCases (org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases)4 JUnit4TestCaseWithNotFilterableRunner (org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner)4 PlainJUnit4TestCaseWithTwoTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Level (java.util.logging.Level)3 LogRecord (java.util.logging.LogRecord)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)3 LogRecordListener (org.junit.platform.commons.logging.LogRecordListener)3 CollectionUtils.getOnlyElement (org.junit.platform.commons.util.CollectionUtils.getOnlyElement)3 DiscoverySelector (org.junit.platform.engine.DiscoverySelector)3