Search in sources :

Example 1 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener in project junit5 by junit-team.

the class VintageTestEngine method execute.

@Override
public void execute(ExecutionRequest request) {
    EngineExecutionListener engineExecutionListener = request.getEngineExecutionListener();
    TestDescriptor engineTestDescriptor = request.getRootTestDescriptor();
    engineExecutionListener.executionStarted(engineTestDescriptor);
    RunnerExecutor runnerExecutor = new RunnerExecutor(engineExecutionListener);
    executeAllChildren(runnerExecutor, engineTestDescriptor);
    engineExecutionListener.executionFinished(engineTestDescriptor, successful());
}
Also used : EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) RunnerExecutor(org.junit.vintage.engine.execution.RunnerExecutor) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 2 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener 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 EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener in project cucumber-jvm by cucumber.

the class CucumberTestEngineTest method createExecutionContext.

@Test
void createExecutionContext() {
    EngineExecutionListener listener = new EmptyEngineExecutionListener();
    ConfigurationParameters configuration = new EmptyConfigurationParameters();
    EngineDiscoveryRequest discoveryRequest = new EmptyEngineDiscoveryRequest(configuration);
    UniqueId id = UniqueId.forEngine(engine.getId());
    TestDescriptor testDescriptor = engine.discover(discoveryRequest, id);
    ExecutionRequest execution = new ExecutionRequest(testDescriptor, listener, configuration);
    assertNotNull(engine.createExecutionContext(execution));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener in project junit5 by junit-team.

the class JupiterEngineDescriptor method prepare.

@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
    ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(context.getConfigurationParameters());
    EngineExecutionListener executionListener = context.getExecutionListener();
    ExtensionContext extensionContext = new JupiterEngineExtensionContext(executionListener, this, context.getConfigurationParameters());
    // @formatter:off
    return context.extend().withExtensionRegistry(extensionRegistry).withExtensionContext(extensionContext).build();
// @formatter:on
}
Also used : EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry)

Example 5 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener 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

EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)8 Test (org.junit.jupiter.api.Test)4 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)3 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 UniqueId (org.junit.platform.engine.UniqueId)2 ReportEntry (org.junit.platform.engine.reporting.ReportEntry)2 DynamicTest (org.junit.jupiter.api.DynamicTest)1 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)1 ClassExtensionContext (org.junit.jupiter.engine.descriptor.ClassExtensionContext)1 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)1 ContainerMatrixEngineDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor)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 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)1 MutableExtensionRegistry (org.junit.jupiter.engine.extension.MutableExtensionRegistry)1 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)1 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)1