use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class DefaultLauncherTests method discoverTestPlanForEngineThatThrowsAnErrorInDiscoverPhase.
@Test
void discoverTestPlanForEngineThatThrowsAnErrorInDiscoverPhase() {
TestEngine engine = new TestEngineStub() {
@Override
public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
throw new Error("ignored");
}
};
TestPlan testPlan = createLauncher(engine).discover(request().build());
assertThat(testPlan.getRoots()).hasSize(0);
}
use of org.junit.platform.engine.UniqueId 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.engine.UniqueId in project junit5 by junit-team.
the class DemoHierarchicalTestEngine method addTest.
public DemoHierarchicalTestDescriptor addTest(Method testMethod, Runnable executeBlock) {
UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", testMethod.getName());
MethodSource source = MethodSource.from(testMethod);
DemoHierarchicalTestDescriptor child = new DemoHierarchicalTestDescriptor(uniqueId, testMethod.getName(), source, executeBlock);
engineDescriptor.addChild(child);
return child;
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class HierarchicalTestExecutorTests method executesDynamicTestDescriptors.
@Test
void executesDynamicTestDescriptors() throws Exception {
UniqueId leafUniqueId = UniqueId.root("leaf", "child leaf");
MyLeaf child = spy(new MyLeaf(leafUniqueId));
MyLeaf dynamicTestDescriptor = spy(new MyLeaf(leafUniqueId.append("dynamic", "child")));
when(child.execute(any(), any())).thenAnswer(invocation -> {
DynamicTestExecutor dynamicTestExecutor = invocation.getArgument(1);
dynamicTestExecutor.execute(dynamicTestDescriptor);
return invocation.getArgument(0);
});
root.addChild(child);
InOrder inOrder = inOrder(listener, root, child, dynamicTestDescriptor);
executor.execute();
ArgumentCaptor<TestExecutionResult> aTestExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
inOrder.verify(listener).executionStarted(root);
inOrder.verify(child).prepare(rootContext);
inOrder.verify(child).shouldBeSkipped(rootContext);
inOrder.verify(listener).executionStarted(child);
inOrder.verify(child).execute(eq(rootContext), any());
inOrder.verify(listener).dynamicTestRegistered(dynamicTestDescriptor);
inOrder.verify(dynamicTestDescriptor).prepare(rootContext);
inOrder.verify(dynamicTestDescriptor).shouldBeSkipped(rootContext);
inOrder.verify(listener).executionStarted(dynamicTestDescriptor);
inOrder.verify(dynamicTestDescriptor).execute(eq(rootContext), any());
inOrder.verify(listener).executionFinished(eq(dynamicTestDescriptor), aTestExecutionResult.capture());
inOrder.verify(listener).executionFinished(eq(child), aTestExecutionResult.capture());
inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
assertThat(aTestExecutionResult.getAllValues()).extracting(TestExecutionResult::getStatus).containsExactly(SUCCESSFUL, SUCCESSFUL);
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class LeafDescriptor method pruneGroup.
@Test
void pruneGroup() {
final AtomicInteger countVisited = new AtomicInteger();
TestDescriptor.Visitor visitor = descriptor -> {
if (descriptor.getUniqueId().equals(UniqueId.root("group", "group1")))
descriptor.removeFromHierarchy();
countVisited.incrementAndGet();
};
engineDescriptor.accept(visitor);
assertEquals(4, countVisited.get(), "Children of pruned element are not visited");
List<UniqueId> visited = new ArrayList<>();
engineDescriptor.accept(descriptor -> visited.add(descriptor.getUniqueId()));
assertEquals(3, visited.size());
assertFalse(visited.contains(UniqueId.root("group", "group1")));
}
Aggregations