use of org.junit.platform.engine.reporting.ReportEntry in project junit5 by junit-team.
the class ExecutionListenerAdapterTests method testReportingEntryPublished.
@Test
void testReportingEntryPublished() {
TestDescriptor testDescriptor = getSampleMethodTestDescriptor();
// cannot mock final classes with mockito
TestPlan testPlan = TestPlan.from(Collections.singleton(testDescriptor));
TestIdentifier testIdentifier = testPlan.getTestIdentifier(testDescriptor.getUniqueId().toString());
// not yet spyable with mockito? -> https://github.com/mockito/mockito/issues/146
MockTestExecutionListener testExecutionListener = new MockTestExecutionListener();
ExecutionListenerAdapter executionListenerAdapter = new ExecutionListenerAdapter(testPlan, testExecutionListener);
ReportEntry entry = ReportEntry.from("one", "two");
executionListenerAdapter.reportingEntryPublished(testDescriptor, entry);
assertThat(testExecutionListener.entry).isEqualTo(entry);
assertThat(testExecutionListener.testIdentifier).isEqualTo(testIdentifier);
}
use of org.junit.platform.engine.reporting.ReportEntry in project junit5 by junit-team.
the class VintageTestEngineExecutionTests method reportsExecutionEventsAroundLifecycleMethods.
@Test
void reportsExecutionEventsAroundLifecycleMethods() {
Class<?> testClass = PlainJUnit4TestCaseWithLifecycleMethods.class;
PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.clear();
EngineExecutionListener listener = new EngineExecutionListener() {
@Override
public void executionStarted(TestDescriptor testDescriptor) {
PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionStarted:" + testDescriptor.getDisplayName());
}
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionFinished:" + testDescriptor.getDisplayName());
}
@Override
public void executionSkipped(TestDescriptor testDescriptor, String reason) {
PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionSkipped:" + testDescriptor.getDisplayName());
}
@Override
public void dynamicTestRegistered(TestDescriptor testDescriptor) {
}
@Override
public void reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry) {
}
};
execute(testClass, listener);
// @formatter:off
assertThat(PlainJUnit4TestCaseWithLifecycleMethods.EVENTS).containsExactly("executionStarted:JUnit Vintage", "executionStarted:" + testClass.getName(), "beforeClass", "executionStarted:failingTest", "before", "failingTest", "after", "executionFinished:failingTest", "executionSkipped:skippedTest", "executionStarted:succeedingTest", "before", "succeedingTest", "after", "executionFinished:succeedingTest", "afterClass", "executionFinished:" + testClass.getName(), "executionFinished:JUnit Vintage");
// @formatter:on
}
use of org.junit.platform.engine.reporting.ReportEntry in project junit5 by junit-team.
the class ExtensionContextTests method reportEntriesArePublishedToExecutionContext.
@Test
@SuppressWarnings("resource")
void reportEntriesArePublishedToExecutionContext() {
ClassTestDescriptor classTestDescriptor = outerClassDescriptor(null);
EngineExecutionListener engineExecutionListener = Mockito.spy(EngineExecutionListener.class);
ExtensionContext extensionContext = new ClassExtensionContext(null, engineExecutionListener, classTestDescriptor, configParams, null);
Map<String, String> map1 = Collections.singletonMap("key", "value");
Map<String, String> map2 = Collections.singletonMap("other key", "other value");
extensionContext.publishReportEntry(map1);
extensionContext.publishReportEntry(map2);
extensionContext.publishReportEntry("3rd key", "third value");
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
Mockito.verify(engineExecutionListener, Mockito.times(3)).reportingEntryPublished(Mockito.eq(classTestDescriptor), entryCaptor.capture());
ReportEntry reportEntry1 = entryCaptor.getAllValues().get(0);
ReportEntry reportEntry2 = entryCaptor.getAllValues().get(1);
ReportEntry reportEntry3 = entryCaptor.getAllValues().get(2);
assertEquals(map1, reportEntry1.getKeyValuePairs());
assertEquals(map2, reportEntry2.getKeyValuePairs());
assertEquals("third value", reportEntry3.getKeyValuePairs().get("3rd key"));
}
Aggregations