use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class DefaultLauncherTests method launcherWillNotExecuteEnginesIfNotIncludedByAnEngineFilter.
@Test
void launcherWillNotExecuteEnginesIfNotIncludedByAnEngineFilter() {
DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
TestDescriptor test1 = firstEngine.addTest("test1", noOp);
DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
TestDescriptor test2 = secondEngine.addTest("test2", noOp);
DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
// @formatter:off
TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(includeEngines("first")).build());
// @formatter:on
assertThat(testPlan.getRoots()).hasSize(1);
TestIdentifier rootIdentifier = testPlan.getRoots().iterator().next();
assertThat(testPlan.getChildren(rootIdentifier.getUniqueId())).hasSize(1);
assertThat(testPlan.getChildren(UniqueId.forEngine("first").toString())).hasSize(1);
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class DefaultLauncherTests method discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase.
@Test
void discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase() {
TestEngine engine = new TestEngineStub() {
@Override
public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
throw new RuntimeException("ignored");
}
};
TestPlan testPlan = createLauncher(engine).discover(request().build());
assertThat(testPlan.getRoots()).hasSize(0);
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class DefaultLauncherTests method launcherWillNotExecuteEnginesExplicitlyExcludedByAnEngineFilter.
@Test
void launcherWillNotExecuteEnginesExplicitlyExcludedByAnEngineFilter() {
DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
TestDescriptor test1 = firstEngine.addTest("test1", noOp);
DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
TestDescriptor test2 = secondEngine.addTest("test2", noOp);
DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
// @formatter:off
TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(excludeEngines("second")).build());
// @formatter:on
assertThat(testPlan.getRoots()).hasSize(1);
TestIdentifier rootIdentifier = testPlan.getRoots().iterator().next();
assertThat(testPlan.getChildren(rootIdentifier.getUniqueId())).hasSize(1);
assertThat(testPlan.getChildren(UniqueId.forEngine("first").toString())).hasSize(1);
}
use of org.junit.platform.launcher.TestPlan 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));
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class DefaultLauncherTests method discoverTestPlanForMultipleEngines.
@Test
void discoverTestPlanForMultipleEngines() {
DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("engine1");
TestDescriptor test1 = firstEngine.addTest("test1", noOp);
DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("engine2");
TestDescriptor test2 = secondEngine.addTest("test2", noOp);
DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).build());
assertThat(testPlan.getRoots()).hasSize(2);
assertThat(testPlan.getChildren(UniqueId.forEngine("engine1").toString())).hasSize(1);
assertThat(testPlan.getChildren(UniqueId.forEngine("engine2").toString())).hasSize(1);
}
Aggregations