Search in sources :

Example 6 with EngineExecutionListener

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

the class DefaultLauncherTests method reportsDynamicTestDescriptorsCorrectly.

@Test
void reportsDynamicTestDescriptorsCorrectly() {
    UniqueId engineId = UniqueId.forEngine(TestEngineSpy.ID);
    UniqueId containerAndTestId = engineId.append("c&t", "c&t");
    UniqueId dynamicTestId = containerAndTestId.append("test", "test");
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            engineDescriptor.addChild(new TestDescriptorStub(containerAndTestId, "c&t") {

                @Override
                public Type getType() {
                    return Type.CONTAINER_AND_TEST;
                }
            });
            return engineDescriptor;
        }

        @Override
        public void execute(ExecutionRequest request) {
            super.execute(request);
            EngineExecutionListener listener = request.getEngineExecutionListener();
            listener.executionStarted(request.getRootTestDescriptor());
            TestDescriptor containerAndTest = getOnlyElement(request.getRootTestDescriptor().getChildren());
            listener.executionStarted(containerAndTest);
            TestDescriptorStub dynamicTest = new TestDescriptorStub(dynamicTestId, "test");
            dynamicTest.setParent(containerAndTest);
            listener.dynamicTestRegistered(dynamicTest);
            listener.executionStarted(dynamicTest);
            listener.executionFinished(dynamicTest, successful());
            listener.executionFinished(containerAndTest, successful());
            listener.executionFinished(request.getRootTestDescriptor(), successful());
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestExecutionListener listener = mock(TestExecutionListener.class);
    launcher.execute(request().build(), listener);
    InOrder inOrder = inOrder(listener);
    ArgumentCaptor<TestPlan> testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
    inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
    TestPlan testPlan = testPlanArgumentCaptor.getValue();
    TestIdentifier engineTestIdentifier = testPlan.getTestIdentifier(engineId.toString());
    TestIdentifier containerAndTestIdentifier = testPlan.getTestIdentifier(containerAndTestId.toString());
    TestIdentifier dynamicTestIdentifier = testPlan.getTestIdentifier(dynamicTestId.toString());
    assertThat(engineTestIdentifier.getParentId()).isEmpty();
    assertThat(containerAndTestIdentifier.getParentId()).contains(engineId.toString());
    assertThat(dynamicTestIdentifier.getParentId()).contains(containerAndTestId.toString());
    inOrder.verify(listener).executionStarted(engineTestIdentifier);
    inOrder.verify(listener).executionStarted(containerAndTestIdentifier);
    inOrder.verify(listener).dynamicTestRegistered(dynamicTestIdentifier);
    inOrder.verify(listener).executionStarted(dynamicTestIdentifier);
    inOrder.verify(listener).executionFinished(dynamicTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(containerAndTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(engineTestIdentifier, successful());
    inOrder.verify(listener).testPlanExecutionFinished(same(testPlan));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) InOrder(org.mockito.InOrder) TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 7 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener in project graylog2-server by Graylog2.

the class ContainerMatrixEngineDescriptor method prepare.

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

Example 8 with EngineExecutionListener

use of org.junit.platform.engine.EngineExecutionListener in project graylog2-server by Graylog2.

the class ContainerMatrixHierarchicalTestExecutor method execute.

Future<Void> execute() {
    ContainerMatrixEngineDescriptor rd = (ContainerMatrixEngineDescriptor) request.getRootTestDescriptor();
    ContainerMatrixEngineDescriptor rootTestDescriptor = new ContainerMatrixEngineDescriptor(rd.getUniqueId(), rd.getDisplayName(), rd.getConfiguration());
    rootTestDescriptor.addChildren(testDescriptors);
    EngineExecutionListener executionListener = this.request.getEngineExecutionListener();
    NodeExecutionAdvisor executionAdvisor = new NodeTreeWalker().walk(rootTestDescriptor);
    NodeTestTaskContext taskContext = new NodeTestTaskContext(executionListener, this.executorService, this.throwableCollectorFactory, executionAdvisor);
    NodeTestTask<C> rootTestTask = new NodeTestTask<>(taskContext, rootTestDescriptor);
    rootTestTask.setParentContext(this.rootContext);
    return this.executorService.submit(rootTestTask);
}
Also used : EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ContainerMatrixEngineDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor)

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