Search in sources :

Example 11 with LauncherDiscoveryRequestBuilder

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

use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project ant by apache.

the class SingleTestClass method createTestRequests.

@Override
List<TestRequest> createTestRequests(final JUnitLauncherTask launcherTask) {
    final Project project = launcherTask.getProject();
    if (!shouldRun(project)) {
        launcherTask.log("Excluding test " + this.testClass + " since it's considered not to run " + "in context of project " + project, Project.MSG_DEBUG);
        return Collections.emptyList();
    }
    final LauncherDiscoveryRequestBuilder requestBuilder = LauncherDiscoveryRequestBuilder.request();
    if (!this.hasMethodsSpecified()) {
        requestBuilder.selectors(DiscoverySelectors.selectClass(this.testClass));
    } else {
        // add specific methods
        final String[] methods = this.getMethods();
        for (final String method : methods) {
            requestBuilder.selectors(DiscoverySelectors.selectMethod(this.testClass, method));
        }
    }
    // add any engine filters
    final String[] enginesToInclude = this.getIncludeEngines();
    if (enginesToInclude != null && enginesToInclude.length > 0) {
        requestBuilder.filters(EngineFilter.includeEngines(enginesToInclude));
    }
    final String[] enginesToExclude = this.getExcludeEngines();
    if (enginesToExclude != null && enginesToExclude.length > 0) {
        requestBuilder.filters(EngineFilter.excludeEngines(enginesToExclude));
    }
    return Collections.singletonList(new TestRequest(this, requestBuilder));
}
Also used : Project(org.apache.tools.ant.Project) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)

Example 13 with LauncherDiscoveryRequestBuilder

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

the class VintageLauncherIntegrationTests method removesCompleteClassIfItHasExcludedTag.

@Test
void removesCompleteClassIfItHasExcludedTag() {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.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)).containsExactly("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) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 14 with LauncherDiscoveryRequestBuilder

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

the class VintageLauncherIntegrationTests method executesOnlyNotExcludedTaggedMethodOfNestedTestClass.

@Test
void executesOnlyNotExcludedTaggedMethodOfNestedTestClass() {
    Class<?> testClass = EnclosedJUnit4TestCase.class;
    Class<?> nestedTestClass = EnclosedJUnit4TestCase.NestedClass.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(excludeTags(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(), "successfulTest");
}
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 15 with LauncherDiscoveryRequestBuilder

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

the class VintageLauncherIntegrationTests method removesCompleteClassIfNoMethodHasMatchingTags.

@Test
void removesCompleteClassIfNoMethodHasMatchingTags() {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(includeTags("wrong-tag"));
    TestPlan testPlan = discover(request);
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).isEmpty();
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactly("JUnit Vintage");
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) 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