use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class DynamicNodeGenerationTests method legacyReportingNames.
@Test
void legacyReportingNames() {
Events dynamicRegistrations = //
executeTests(selectMethod(MyDynamicTestCase.class, "nestedDynamicContainers")).allEvents().dynamicallyRegistered();
// @formatter:off
Stream<String> legacyReportingNames = dynamicRegistrations.map(Event::getTestDescriptor).map(TestDescriptor::getLegacyReportingName);
assertThat(legacyReportingNames).containsExactly("nestedDynamicContainers()[1]", "nestedDynamicContainers()[1][1]", "nestedDynamicContainers()[1][1][1]", "nestedDynamicContainers()[1][1][2]");
// @formatter:on
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class DynamicNodeGenerationTests method testFactoryMethodsAreCorrectlyDiscoveredForClassSelector.
@Test
void testFactoryMethodsAreCorrectlyDiscoveredForClassSelector() {
LauncherDiscoveryRequest request = request().selectors(selectClass(MyDynamicTestCase.class)).build();
TestDescriptor engineDescriptor = discoverTests(request);
assertThat(engineDescriptor.getDescendants()).as("# resolved test descriptors").hasSize(13);
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class AbstractJupiterTestEngineTests method discoverUniqueId.
protected UniqueId discoverUniqueId(Class<?> clazz, String methodName) {
TestDescriptor engineDescriptor = discoverTests(selectMethod(clazz, methodName));
Set<? extends TestDescriptor> descendants = engineDescriptor.getDescendants();
// @formatter:off
TestDescriptor testDescriptor = descendants.stream().skip(descendants.size() - 1).findFirst().orElseGet(() -> fail("no descendants"));
// @formatter:on
return testDescriptor.getUniqueId();
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class LeafDescriptor method setParentToOtherInstance.
@Test
void setParentToOtherInstance() {
TestDescriptor newEngine = new EngineDescriptor(UniqueId.forEngine("newEngine"), "newEngine");
var group = engineDescriptor.getChildren().iterator().next();
assertSame(engineDescriptor, group.getParent().orElseThrow(Error::new));
group.setParent(newEngine);
assertSame(newEngine, group.getParent().orElseThrow(Error::new));
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class MethodSelectorResolver method resolve.
private Resolution resolve(Context context, List<Class<?>> enclosingClasses, Class<?> testClass, Supplier<Method> methodSupplier, BiFunction<TestDescriptor, Supplier<Set<? extends DiscoverySelector>>, Match> matchFactory) {
if (!testClassPredicate.test(testClass)) {
return unresolved();
}
Method method = methodSupplier.get();
// @formatter:off
Set<Match> matches = Arrays.stream(MethodType.values()).map(methodType -> methodType.resolve(enclosingClasses, testClass, method, context, configuration)).filter(Optional::isPresent).map(Optional::get).map(testDescriptor -> matchFactory.apply(testDescriptor, expansionCallback(testDescriptor))).collect(toSet());
// @formatter:on
if (matches.size() > 1) {
logger.warn(() -> {
Stream<TestDescriptor> testDescriptors = matches.stream().map(Match::getTestDescriptor);
return String.format("Possible configuration error: method [%s] resulted in multiple TestDescriptors %s. " + "This is typically the result of annotating a method with multiple competing annotations " + "such as @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, etc.", method.toGenericString(), testDescriptors.map(d -> d.getClass().getName()).collect(toList()));
});
}
return matches.isEmpty() ? unresolved() : matches(matches);
}
Aggregations