Search in sources :

Example 6 with TestPlan

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

the class LauncherFactoryTests method create.

@Test
void create() {
    LauncherDiscoveryRequest discoveryRequest = createLauncherDiscoveryRequestForBothStandardEngineExampleClasses();
    TestPlan testPlan = LauncherFactory.create().discover(discoveryRequest);
    Set<TestIdentifier> roots = testPlan.getRoots();
    assertThat(roots).hasSize(2);
    // @formatter:off
    List<String> ids = roots.stream().map(TestIdentifier::getUniqueId).collect(toList());
    // @formatter:on
    assertThat(ids).containsOnly("[engine:junit-vintage]", "[engine:junit-jupiter]");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 7 with TestPlan

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

the class RunListenerAdapterTests method notifiedWithParentDisplayNameWhenTestClassUnknown.

@Test
void notifiedWithParentDisplayNameWhenTestClassUnknown() throws Exception {
    // Set up a test plan
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(plan);
    // Use the test plan to set up child with parent.
    final String parentDisplay = "I am your father";
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, parentDisplay, null);
    adapter.executionStarted(child);
    // Check that the adapter has informed Surefire that the test has been invoked,
    // with the parent name as source (since the test case itself had no source).
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testStarting(entryCaptor.capture());
    assertEquals(parentDisplay, entryCaptor.getValue().getSourceName());
}
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 8 with TestPlan

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

the class RunListenerAdapterTests method notifiedWithCorrectNamesWhenClassExecutionFailed.

@Test
void notifiedWithCorrectNamesWhenClassExecutionFailed() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    adapter.executionFinished(identifiersAsParentOnTestPlan(testPlan, newEngineDescriptor(), newClassDescriptor()), TestExecutionResult.failed(new AssertionError()));
    verify(listener).testFailed(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MyTestClass.class.getTypeName(), entry.getSourceName());
    assertNotNull(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) Test(org.junit.jupiter.api.Test)

Example 9 with TestPlan

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

the class RunListenerAdapterTests method notifiedForTestSetForSingleNodeEngine.

@Test
void notifiedForTestSetForSingleNodeEngine() {
    EngineDescriptor engine = new EngineDescriptor(UniqueId.forEngine("engine"), "engine") {

        @Override
        public Type getType() {
            return Type.TEST;
        }
    };
    TestPlan plan = TestPlan.from(Collections.singletonList(engine));
    adapter.testPlanExecutionStarted(plan);
    adapter.executionStarted(TestIdentifier.from(engine));
    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "engine"));
    inOrder.verify(listener).testStarting(new SimpleReportEntry("<unrooted>", "engine"));
    inOrder.verifyNoMoreInteractions();
    adapter.executionFinished(TestIdentifier.from(engine), successful());
    inOrder = inOrder(listener);
    inOrder.verify(listener).testSucceeded(new SimpleReportEntry("<unrooted>", "engine"));
    inOrder.verify(listener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "engine"));
    inOrder.verifyNoMoreInteractions();
}
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) Test(org.junit.jupiter.api.Test)

Example 10 with TestPlan

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

the class RunListenerAdapterTests method notifiedWithCorrectNamesWhenClassExecutionSkipped.

@Test
void notifiedWithCorrectNamesWhenClassExecutionSkipped() 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 classIdentifier = identifiersAsParentOnTestPlan(testPlan, newEngineDescriptor(), newClassDescriptor());
    adapter.executionSkipped(classIdentifier, "test");
    verify(listener).testSkipped(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertTrue(MyTestClass.class.getTypeName().contains(entry.getName()));
    assertEquals(MyTestClass.class.getTypeName(), entry.getSourceName());
}
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)

Aggregations

TestPlan (org.junit.platform.launcher.TestPlan)47 Test (org.junit.jupiter.api.Test)38 TestIdentifier (org.junit.platform.launcher.TestIdentifier)24 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)16 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)16 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)10 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)9 UniqueId (org.junit.platform.engine.UniqueId)8 Launcher (org.junit.platform.launcher.Launcher)8 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 TestDescriptor (org.junit.platform.engine.TestDescriptor)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)4 TestEngine (org.junit.platform.engine.TestEngine)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4