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());
}
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());
}
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;
}
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());
}
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");
}
Aggregations