Search in sources :

Example 46 with TestPlan

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

the class DefaultLauncherTests method launcherWillNotExecuteEnginesIfNotIncludedByAnEngineFilter.

@Test
void launcherWillNotExecuteEnginesIfNotIncludedByAnEngineFilter() {
    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")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier rootIdentifier = testPlan.getRoots().iterator().next();
    assertThat(testPlan.getChildren(rootIdentifier.getUniqueId())).hasSize(1);
    assertThat(testPlan.getChildren(UniqueId.forEngine("first").toString())).hasSize(1);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 47 with TestPlan

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

the class DefaultLauncherTests method discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase.

@Test
void discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase() {
    TestEngine engine = new TestEngineStub() {

        @Override
        public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            throw new RuntimeException("ignored");
        }
    };
    TestPlan testPlan = createLauncher(engine).discover(request().build());
    assertThat(testPlan.getRoots()).hasSize(0);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineStub(org.junit.platform.engine.test.TestEngineStub) Test(org.junit.jupiter.api.Test)

Example 48 with TestPlan

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

the class DefaultLauncherTests method launcherWillNotExecuteEnginesExplicitlyExcludedByAnEngineFilter.

@Test
void launcherWillNotExecuteEnginesExplicitlyExcludedByAnEngineFilter() {
    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(excludeEngines("second")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier rootIdentifier = testPlan.getRoots().iterator().next();
    assertThat(testPlan.getChildren(rootIdentifier.getUniqueId())).hasSize(1);
    assertThat(testPlan.getChildren(UniqueId.forEngine("first").toString())).hasSize(1);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 49 with TestPlan

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

the class DefaultLauncherTests method reportsDynamicTestDescriptorsCorrectly.

@Test
void reportsDynamicTestDescriptorsCorrectly() {
    UniqueId engineId = UniqueId.forEngine(TestEngineSpy.ID);
    UniqueId containerAndTestId = engineId.append("c&t", "c&t");
    UniqueId dynamicTestId = containerAndTestId.append("test", "test");
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            engineDescriptor.addChild(new TestDescriptorStub(containerAndTestId, "c&t") {

                @Override
                public Type getType() {
                    return Type.CONTAINER_AND_TEST;
                }
            });
            return engineDescriptor;
        }

        @Override
        public void execute(ExecutionRequest request) {
            super.execute(request);
            EngineExecutionListener listener = request.getEngineExecutionListener();
            listener.executionStarted(request.getRootTestDescriptor());
            TestDescriptor containerAndTest = getOnlyElement(request.getRootTestDescriptor().getChildren());
            listener.executionStarted(containerAndTest);
            TestDescriptorStub dynamicTest = new TestDescriptorStub(dynamicTestId, "test");
            dynamicTest.setParent(containerAndTest);
            listener.dynamicTestRegistered(dynamicTest);
            listener.executionStarted(dynamicTest);
            listener.executionFinished(dynamicTest, successful());
            listener.executionFinished(containerAndTest, successful());
            listener.executionFinished(request.getRootTestDescriptor(), successful());
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestExecutionListener listener = mock(TestExecutionListener.class);
    launcher.execute(request().build(), listener);
    InOrder inOrder = inOrder(listener);
    ArgumentCaptor<TestPlan> testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
    inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
    TestPlan testPlan = testPlanArgumentCaptor.getValue();
    TestIdentifier engineTestIdentifier = testPlan.getTestIdentifier(engineId.toString());
    TestIdentifier containerAndTestIdentifier = testPlan.getTestIdentifier(containerAndTestId.toString());
    TestIdentifier dynamicTestIdentifier = testPlan.getTestIdentifier(dynamicTestId.toString());
    assertThat(engineTestIdentifier.getParentId()).isEmpty();
    assertThat(containerAndTestIdentifier.getParentId()).contains(engineId.toString());
    assertThat(dynamicTestIdentifier.getParentId()).contains(containerAndTestId.toString());
    inOrder.verify(listener).executionStarted(engineTestIdentifier);
    inOrder.verify(listener).executionStarted(containerAndTestIdentifier);
    inOrder.verify(listener).dynamicTestRegistered(dynamicTestIdentifier);
    inOrder.verify(listener).executionStarted(dynamicTestIdentifier);
    inOrder.verify(listener).executionFinished(dynamicTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(containerAndTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(engineTestIdentifier, successful());
    inOrder.verify(listener).testPlanExecutionFinished(same(testPlan));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) InOrder(org.mockito.InOrder) TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 50 with TestPlan

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

the class DefaultLauncherTests method discoverTestPlanForMultipleEngines.

@Test
void discoverTestPlanForMultipleEngines() {
    DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("engine1");
    TestDescriptor test1 = firstEngine.addTest("test1", noOp);
    DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("engine2");
    TestDescriptor test2 = secondEngine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
    TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).build());
    assertThat(testPlan.getRoots()).hasSize(2);
    assertThat(testPlan.getChildren(UniqueId.forEngine("engine1").toString())).hasSize(1);
    assertThat(testPlan.getChildren(UniqueId.forEngine("engine2").toString())).hasSize(1);
}
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)

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