use of org.junit.platform.fakes.TestEngineSpy in project junit5 by junit-team.
the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.
@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
var engine = new TestEngineSpy() {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
super.discover(discoveryRequest, uniqueId);
var engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
var 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;
}
};
var launcher = createLauncher(engine);
var testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
assertThat(testPlan.getRoots()).hasSize(1);
var engineIdentifier = getOnlyElement(testPlan.getRoots());
assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
use of org.junit.platform.fakes.TestEngineSpy in project junit5 by junit-team.
the class DefaultLauncherTests method reportsDynamicTestDescriptorsCorrectly.
@Test
void reportsDynamicTestDescriptorsCorrectly() {
var engineId = UniqueId.forEngine(TestEngineSpy.ID);
var containerAndTestId = engineId.append("c&t", "c&t");
var dynamicTestId = containerAndTestId.append("test", "test");
var engine = new TestEngineSpy() {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
super.discover(discoveryRequest, uniqueId);
var 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);
var listener = request.getEngineExecutionListener();
listener.executionStarted(request.getRootTestDescriptor());
var containerAndTest = getOnlyElement(request.getRootTestDescriptor().getChildren());
listener.executionStarted(containerAndTest);
var 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());
}
};
var launcher = createLauncher(engine);
var listener = mock(TestExecutionListener.class);
launcher.execute(request().build(), listener);
var inOrder = inOrder(listener);
var testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
var testPlan = testPlanArgumentCaptor.getValue();
var engineTestIdentifier = testPlan.getTestIdentifier(engineId.toString());
var containerAndTestIdentifier = testPlan.getTestIdentifier(containerAndTestId.toString());
var 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.fakes.TestEngineSpy in project junit5 by junit-team.
the class DefaultLauncherTests method testPlanThrowsExceptionWhenModified.
@Test
@SuppressWarnings("deprecation")
void testPlanThrowsExceptionWhenModified() {
TestEngine engine = new TestEngineSpy();
var launcher = createLauncher(engine);
var testPlan = launcher.discover(request().build());
var engineIdentifier = getOnlyElement(testPlan.getRoots());
var engineUniqueId = UniqueId.parse(engineIdentifier.getUniqueId());
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1);
var addedIdentifier = TestIdentifier.from(new TestDescriptorStub(engineUniqueId.append("test", "test2"), "test2"));
var exception = assertThrows(JUnitException.class, () -> testPlan.add(addedIdentifier));
assertThat(exception).hasMessage("Unsupported attempt to modify the TestPlan was detected. " + "Please contact your IDE/tool vendor and request a fix or downgrade to JUnit 5.7.x (see https://github.com/junit-team/junit5/issues/1732 for details).");
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1).doesNotContain(addedIdentifier);
}
Aggregations