Search in sources :

Example 11 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier 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)

Example 12 with TestIdentifier

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

the class RunListenerAdapterTests method stackTraceWriterDefaultsToTestClass.

@Test
void stackTraceWriterDefaultsToTestClass() throws Exception {
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Some Plan")));
    adapter.testPlanExecutionStarted(plan);
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", null);
    adapter.executionFinished(child, TestExecutionResult.failed(new RuntimeException("message")));
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testError(entryCaptor.capture());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().smartTrimmedStackTrace());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().writeTraceToString());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().writeTrimmedTraceToString());
}
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 13 with TestIdentifier

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

the class RunListenerAdapterTests method newSourcelessChildIdentifierWithParent.

private static TestIdentifier newSourcelessChildIdentifierWithParent(TestPlan testPlan, String parentDisplay, TestSource parentTestSource) {
    // A parent test identifier with a name.
    TestDescriptor parent = mock(TestDescriptor.class);
    when(parent.getUniqueId()).thenReturn(newId());
    when(parent.getDisplayName()).thenReturn(parentDisplay);
    when(parent.getLegacyReportingName()).thenReturn(parentDisplay);
    when(parent.getSource()).thenReturn(Optional.ofNullable(parentTestSource));
    when(parent.getType()).thenReturn(Type.CONTAINER);
    TestIdentifier parentId = TestIdentifier.from(parent);
    // The (child) test case that is to be executed as part of a test plan.
    TestDescriptor child = mock(TestDescriptor.class);
    when(child.getUniqueId()).thenReturn(newId());
    when(child.getType()).thenReturn(Type.TEST);
    when(child.getLegacyReportingName()).thenReturn("child");
    // Ensure the child source is null yet that there is a parent -- the special case to be tested.
    when(child.getSource()).thenReturn(Optional.empty());
    when(child.getParent()).thenReturn(Optional.of(parent));
    TestIdentifier childId = TestIdentifier.from(child);
    testPlan.add(childId);
    testPlan.add(parentId);
    return childId;
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) 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)

Example 14 with TestIdentifier

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

the class RunListenerAdapterTests method stackTraceWriterPresentWhenParentHasSource.

@Test
void stackTraceWriterPresentWhenParentHasSource() throws Exception {
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Some Plan")));
    adapter.testPlanExecutionStarted(plan);
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", ClassSource.from(MyTestClass.class));
    adapter.executionFinished(child, TestExecutionResult.failed(new RuntimeException()));
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testError(entryCaptor.capture());
    assertNotNull(entryCaptor.getValue().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 15 with TestIdentifier

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

the class VintageLauncherIntegrationTests method executesIncludedTaggedMethodOfNestedTestClass.

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

Aggregations

TestIdentifier (org.junit.platform.launcher.TestIdentifier)53 Test (org.junit.jupiter.api.Test)29 TestPlan (org.junit.platform.launcher.TestPlan)23 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)17 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 LinkedHashMap (java.util.LinkedHashMap)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Map (java.util.Map)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)3 MethodTestDescriptor (org.junit.jupiter.engine.descriptor.MethodTestDescriptor)3 Launcher (org.junit.platform.launcher.Launcher)3