Search in sources :

Example 1 with TestEngineSpy

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

the class DefaultLauncherTests method withAdditionalListener.

@Test
void withAdditionalListener() {
    TestEngineSpy engine = new TestEngineSpy();
    SummaryGeneratingListener listener = new SummaryGeneratingListener();
    DefaultLauncher launcher = createLauncher(engine);
    launcher.execute(request().build(), listener);
    assertThat(listener.getSummary()).isNotNull();
    assertThat(listener.getSummary().getContainersFoundCount()).isEqualTo(1);
    assertThat(listener.getSummary().getTestsFoundCount()).isEqualTo(1);
}
Also used : SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 2 with TestEngineSpy

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

the class DefaultLauncherTests method withoutConfigurationParameters_launcherPassesEmptyConfigurationParametersIntoTheExecutionRequest.

@Test
void withoutConfigurationParameters_launcherPassesEmptyConfigurationParametersIntoTheExecutionRequest() {
    TestEngineSpy engine = new TestEngineSpy();
    DefaultLauncher launcher = createLauncher(engine);
    launcher.execute(request().build());
    ConfigurationParameters configurationParameters = engine.requestForExecution.getConfigurationParameters();
    assertThat(configurationParameters.get("key").isPresent()).isFalse();
    assertThat(configurationParameters.size()).isEqualTo(0);
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 3 with TestEngineSpy

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

the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.

@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            TestDescriptorStub containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {

                @Override
                public Type getType() {
                    return Type.CONTAINER;
                }
            };
            containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
            engineDescriptor.addChild(containerDescriptor);
            return engineDescriptor;
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestPlan testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier engineIdentifier = getOnlyElement(testPlan.getRoots());
    assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestPlan(org.junit.platform.launcher.TestPlan) EngineFilter.excludeEngines(org.junit.platform.launcher.EngineFilter.excludeEngines) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestExecutionResult.successful(org.junit.platform.engine.TestExecutionResult.successful) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ArgumentCaptor(org.mockito.ArgumentCaptor) LauncherFactoryForTestingPurposesOnly.createLauncher(org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) InOrder(org.mockito.InOrder) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) JUnitException(org.junit.platform.commons.JUnitException) TestEngineStub(org.junit.platform.engine.test.TestEngineStub) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 4 with TestEngineSpy

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

the class DefaultLauncherTests method withConfigurationParameters_launcherPassesPopulatedConfigurationParametersIntoTheExecutionRequest.

@Test
void withConfigurationParameters_launcherPassesPopulatedConfigurationParametersIntoTheExecutionRequest() {
    TestEngineSpy engine = new TestEngineSpy();
    DefaultLauncher launcher = createLauncher(engine);
    launcher.execute(request().configurationParameter("key", "value").build());
    ConfigurationParameters configurationParameters = engine.requestForExecution.getConfigurationParameters();
    assertThat(configurationParameters.size()).isEqualTo(1);
    assertThat(configurationParameters.get("key").isPresent()).isTrue();
    assertThat(configurationParameters.get("key").get()).isEqualTo("value");
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 5 with TestEngineSpy

use of org.junit.platform.engine.test.TestEngineSpy 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)

Aggregations

Test (org.junit.jupiter.api.Test)6 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)6 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)4 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestDescriptor (org.junit.platform.engine.TestDescriptor)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)2 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 TestIdentifier (org.junit.platform.launcher.TestIdentifier)2 TestPlan (org.junit.platform.launcher.TestPlan)2 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)2 InOrder (org.mockito.InOrder)2 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1