Search in sources :

Example 1 with TestPlan

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

the class DefaultLauncherTests method launcherWillNotExecuteEnginesExplicitlyIncludedViaMultipleCompetingEngineFilters.

@Test
void launcherWillNotExecuteEnginesExplicitlyIncludedViaMultipleCompetingEngineFilters() {
    DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
    TestDescriptor test1 = firstEngine.addTest("test1", noOp);
    DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
    TestDescriptor test2 = secondEngine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
    // @formatter:off
    TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(includeEngines("first"), includeEngines("second")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).isEmpty();
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with TestPlan

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

the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.

@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            TestDescriptorStub containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {

                @Override
                public Type getType() {
                    return Type.CONTAINER;
                }
            };
            containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
            engineDescriptor.addChild(containerDescriptor);
            return engineDescriptor;
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestPlan testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier engineIdentifier = getOnlyElement(testPlan.getRoots());
    assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestPlan(org.junit.platform.launcher.TestPlan) EngineFilter.excludeEngines(org.junit.platform.launcher.EngineFilter.excludeEngines) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestExecutionResult.successful(org.junit.platform.engine.TestExecutionResult.successful) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ArgumentCaptor(org.mockito.ArgumentCaptor) LauncherFactoryForTestingPurposesOnly.createLauncher(org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) InOrder(org.mockito.InOrder) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) JUnitException(org.junit.platform.commons.JUnitException) TestEngineStub(org.junit.platform.engine.test.TestEngineStub) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 3 with TestPlan

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

the class DefaultLauncherTests method launcherWillExecuteAllEnginesExplicitlyIncludedViaSingleEngineFilter.

@Test
void launcherWillExecuteAllEnginesExplicitlyIncludedViaSingleEngineFilter() {
    DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
    TestDescriptor test1 = firstEngine.addTest("test1", noOp);
    DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
    TestDescriptor test2 = secondEngine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
    // @formatter:off
    TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(includeEngines("first", "second")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).hasSize(2);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with TestPlan

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

the class DefaultLauncherTests method launcherAppliesPostDiscoveryFilters.

@Test
void launcherAppliesPostDiscoveryFilters() {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("myEngine");
    DemoHierarchicalTestDescriptor test1 = engine.addTest("test1", noOp);
    engine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(engine);
    PostDiscoveryFilter includeWithUniqueIdContainsTest = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("test")), () -> "filter1");
    PostDiscoveryFilter includeWithUniqueIdContains1 = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("1")), () -> "filter2");
    TestPlan testPlan = // 
    launcher.discover(// 
    request().selectors(// 
    selectPackage("any")).filters(includeWithUniqueIdContainsTest, // 
    includeWithUniqueIdContains1).build());
    assertThat(testPlan.getChildren(UniqueId.forEngine("myEngine").toString())).hasSize(1);
    assertThat(testPlan.getTestIdentifier(test1.getUniqueId().toString())).isNotNull();
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) Test(org.junit.jupiter.api.Test)

Example 5 with TestPlan

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

the class DefaultLauncherTests method discoverEmptyTestPlanWithEngineWithoutAnyTests.

@Test
void discoverEmptyTestPlanWithEngineWithoutAnyTests() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine());
    TestPlan testPlan = launcher.discover(request().build());
    assertThat(testPlan.getRoots()).hasSize(1);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Aggregations

TestPlan (org.junit.platform.launcher.TestPlan)55 Test (org.junit.jupiter.api.Test)48 TestIdentifier (org.junit.platform.launcher.TestIdentifier)27 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)15 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)14 TestDescriptor (org.junit.platform.engine.TestDescriptor)13 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)13 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)11 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)10 UniqueId (org.junit.platform.engine.UniqueId)10 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)9 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 Launcher (org.junit.platform.launcher.Launcher)7 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)7 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 TestEngine (org.junit.platform.engine.TestEngine)5