use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.
the class TestRunTests method registersDynamicTestDescriptors.
@Test
void registersDynamicTestDescriptors() throws Exception {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
UniqueId dynamicTestId = runnerId.append(SEGMENT_TYPE_DYNAMIC, "dynamicTest");
Description dynamicDescription = createTestDescription(testClass, "dynamicTest");
VintageTestDescriptor dynamicTestDescriptor = new VintageTestDescriptor(dynamicTestId, dynamicDescription);
TestRun testRun = new TestRun(runnerTestDescriptor);
testRun.registerDynamicTest(dynamicTestDescriptor);
assertThat(testRun.lookupTestDescriptor(dynamicDescription)).contains(dynamicTestDescriptor);
assertTrue(testRun.isDescendantOfRunnerTestDescriptor(dynamicTestDescriptor));
}
use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.
the class RunListenerAdapter method registerDynamicTestDescriptor.
private VintageTestDescriptor registerDynamicTestDescriptor(Description description) {
// workaround for dynamic children as used by Spock's Runner
TestDescriptor parent = findParent(description);
UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description));
VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description);
parent.addChild(dynamicDescriptor);
testRun.registerDynamicTest(dynamicDescriptor);
dynamicTestRegistered(dynamicDescriptor);
return dynamicDescriptor;
}
use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.
the class TestRunTests method returnsEmptyOptionalForUnknownDescriptions.
@Test
void returnsEmptyOptionalForUnknownDescriptions() throws Exception {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
Description unknownDescription = createTestDescription(testClass, "dynamicTest");
TestRun testRun = new TestRun(runnerTestDescriptor);
Optional<VintageTestDescriptor> testDescriptor = testRun.lookupTestDescriptor(unknownDescription);
assertThat(testDescriptor).isEmpty();
}
use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.
the class TestClassRequestResolver method addChildrenRecursively.
private void addChildrenRecursively(VintageTestDescriptor parent) {
List<Description> children = parent.getDescription().getChildren();
// Use LinkedHashMap to preserve order, ArrayList for fast access by index
Map<String, List<Description>> childrenByUniqueId = children.stream().collect(groupingBy(uniqueIdReader.andThen(uniqueIdStringifier), LinkedHashMap::new, toCollection(ArrayList::new)));
for (Entry<String, List<Description>> entry : childrenByUniqueId.entrySet()) {
String uniqueId = entry.getKey();
List<Description> childrenWithSameUniqueId = entry.getValue();
IntFunction<String> uniqueIdGenerator = determineUniqueIdGenerator(uniqueId, childrenWithSameUniqueId);
for (int index = 0; index < childrenWithSameUniqueId.size(); index++) {
String reallyUniqueId = uniqueIdGenerator.apply(index);
Description description = childrenWithSameUniqueId.get(index);
UniqueId id = parent.getUniqueId().append(VintageTestDescriptor.SEGMENT_TYPE_TEST, reallyUniqueId);
VintageTestDescriptor child = new VintageTestDescriptor(id, description);
parent.addChild(child);
addChildrenRecursively(child);
}
}
}
Aggregations