Search in sources :

Example 1 with ReportEntry

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);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.junit.platform.engine.reporting.ReportEntry) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DemoMethodTestDescriptor(org.junit.platform.engine.support.descriptor.DemoMethodTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with ReportEntry

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
}
Also used : PlainJUnit4TestCaseWithLifecycleMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithLifecycleMethods) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ReportEntry(org.junit.platform.engine.reporting.ReportEntry) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 3 with ReportEntry

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"));
}
Also used : EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) ReportEntry(org.junit.platform.engine.reporting.ReportEntry) MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

Test (org.junit.jupiter.api.Test)3 ReportEntry (org.junit.platform.engine.reporting.ReportEntry)3 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 TestDescriptor (org.junit.platform.engine.TestDescriptor)2 DynamicTest (org.junit.jupiter.api.DynamicTest)1 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 ClassExtensionContext (org.junit.jupiter.engine.descriptor.ClassExtensionContext)1 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)1 JupiterEngineExtensionContext (org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext)1 MethodExtensionContext (org.junit.jupiter.engine.descriptor.MethodExtensionContext)1 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)1 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)1 DemoMethodTestDescriptor (org.junit.platform.engine.support.descriptor.DemoMethodTestDescriptor)1 TestIdentifier (org.junit.platform.launcher.TestIdentifier)1 TestPlan (org.junit.platform.launcher.TestPlan)1 PlainJUnit4TestCaseWithLifecycleMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithLifecycleMethods)1