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);
}
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);
}
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();
}
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");
}
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));
}
Aggregations