Search in sources :

Example 1 with ReportEntry

use of org.apache.maven.surefire.report.ReportEntry 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 2 with ReportEntry

use of org.apache.maven.surefire.report.ReportEntry 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 3 with ReportEntry

use of org.apache.maven.surefire.report.ReportEntry 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 4 with ReportEntry

use of org.apache.maven.surefire.report.ReportEntry 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 5 with ReportEntry

use of org.apache.maven.surefire.report.ReportEntry 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)

Aggregations

ReportEntry (org.apache.maven.surefire.report.ReportEntry)9 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)9 Test (org.junit.jupiter.api.Test)9 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 TestIdentifier (org.junit.platform.launcher.TestIdentifier)7 TestPlan (org.junit.platform.launcher.TestPlan)7 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)1 RunListener (org.apache.maven.surefire.report.RunListener)1 TestsToRun (org.apache.maven.surefire.util.TestsToRun)1 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)1