Search in sources :

Example 51 with TestPlan

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

the class DefaultLauncherTests method discoverTestPlanForEngineThatReturnsNullForItsRootDescriptor.

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

        @Override
        public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            return null;
        }
    };
    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 52 with TestPlan

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

the class RunListenerAdapterTests method notifiedWithCorrectNamesWhenMethodExecutionStarted.

@Test
void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    TestIdentifier methodIdentifier = identifiersAsParentOnTestPlan(testPlan, newClassDescriptor(), newMethodDescriptor());
    adapter.executionStarted(methodIdentifier);
    verify(listener).testStarting(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MY_TEST_METHOD_NAME, entry.getName());
    assertEquals(MyTestClass.class.getName(), entry.getSourceName());
    assertNull(entry.getStackTraceWriter());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 53 with TestPlan

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

the class RunListenerAdapterTests method notifiedLazilyForTestSetWhenFirstTestWithoutClassDescriptorParentStarted.

@Test
void notifiedLazilyForTestSetWhenFirstTestWithoutClassDescriptorParentStarted() {
    EngineDescriptor engine = newEngineDescriptor();
    TestDescriptor parent = newTestDescriptor(engine.getUniqueId().append("container", "noClass"), "parent", Type.CONTAINER);
    engine.addChild(parent);
    TestDescriptor child1 = newTestDescriptor(parent.getUniqueId().append("test", "child1"), "child1", Type.TEST);
    parent.addChild(child1);
    TestDescriptor child2 = newTestDescriptor(parent.getUniqueId().append("test", "child2"), "child2", Type.TEST);
    parent.addChild(child2);
    TestPlan plan = TestPlan.from(Collections.singletonList(engine));
    adapter.testPlanExecutionStarted(plan);
    adapter.executionStarted(TestIdentifier.from(engine));
    adapter.executionStarted(TestIdentifier.from(parent));
    verifyZeroInteractions(listener);
    adapter.executionStarted(TestIdentifier.from(child1));
    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "parent"));
    inOrder.verify(listener).testStarting(new SimpleReportEntry("parent", "child1"));
    inOrder.verifyNoMoreInteractions();
    adapter.executionFinished(TestIdentifier.from(child1), successful());
    verify(listener).testSucceeded(new SimpleReportEntry("parent", "child1"));
    verifyNoMoreInteractions(listener);
    adapter.executionStarted(TestIdentifier.from(child2));
    verify(listener).testStarting(new SimpleReportEntry("parent", "child2"));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(child2), successful());
    verify(listener).testSucceeded(new SimpleReportEntry("parent", "child2"));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(parent), successful());
    verify(listener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "parent"));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(engine), successful());
    verifyNoMoreInteractions(listener);
}
Also used : SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) InOrder(org.mockito.InOrder) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 54 with TestPlan

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

the class RunListenerAdapterTests method notifiedWithCompatibleNameForMethodWithArguments.

@Test
void notifiedWithCompatibleNameForMethodWithArguments() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    TestIdentifier methodIdentifier = identifiersAsParentOnTestPlan(testPlan, newClassDescriptor(), newMethodDescriptor(String.class));
    adapter.executionStarted(methodIdentifier);
    verify(listener).testStarting(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MY_TEST_METHOD_NAME + "{String}", entry.getName());
    assertEquals(MyTestClass.class.getName(), entry.getSourceName());
    assertNull(entry.getStackTraceWriter());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 55 with TestPlan

use of org.junit.platform.launcher.TestPlan in project spock by spockframework.

the class SpockHelloWorldTest method verifyErrorExample.

@Test
void verifyErrorExample() {
    Launcher launcher = LauncherFactory.create(LauncherConfig.builder().enableTestEngineAutoRegistration(false).enableTestExecutionListenerAutoRegistration(false).addTestEngines(new SpockEngine()).build());
    TestPlan testPlan = launcher.discover(LauncherDiscoveryRequestBuilder.request().selectors(selectClass(ErrorTestCase.class)).build());
    assertEquals(1, testPlan.getChildren(testPlan.getRoots().iterator().next()).size());
    execute(selectClass(StepwiseTestCase.class), stats -> stats.started(4).succeeded(3).failed(1).skipped(1));
}
Also used : SpockEngine(org.spockframework.runtime.SpockEngine) TestPlan(org.junit.platform.launcher.TestPlan) Launcher(org.junit.platform.launcher.Launcher) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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