use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class DiscoveryFilterApplierTests method packageNameFilterInclude_matchingPackagesAreIncluded.
@Test
void packageNameFilterInclude_matchingPackagesAreIncluded() {
// @formatter:off
TestDescriptor engineDescriptor = engineDescriptor().with(classTestDescriptor("matching", MatchingClass.class)).build();
applyClassNamePredicate(engineDescriptor, includePackageNames("org.junit.jupiter.engine"));
assertThat(engineDescriptor.getDescendants()).extracting(TestDescriptor::getUniqueId).containsExactly(UniqueId.root("class", "matching"));
// @formatter:on
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class JavaElementsResolver method resolveAllSegments.
/**
* Attempt to resolve all segments for the supplied unique ID.
*/
private Deque<TestDescriptor> resolveAllSegments(UniqueId uniqueId) {
List<Segment> segments = uniqueId.getSegments();
Deque<TestDescriptor> resolvedDescriptors = new LinkedList<>();
resolvedDescriptors.addFirst(this.engineDescriptor);
for (int index = 1; index < segments.size() && resolvedDescriptors.size() == index; index++) {
Segment segment = segments.get(index);
TestDescriptor parent = resolvedDescriptors.getLast();
UniqueId partialUniqueId = parent.getUniqueId().append(segment);
Optional<TestDescriptor> resolvedDescriptor = findTestDescriptorByUniqueId(partialUniqueId);
if (!resolvedDescriptor.isPresent()) {
// @formatter:off
resolvedDescriptor = this.resolvers.stream().map(resolver -> resolver.resolveUniqueId(segment, parent)).filter(Optional::isPresent).map(Optional::get).findFirst();
// @formatter:on
resolvedDescriptor.ifPresent(parent::addChild);
}
resolvedDescriptor.ifPresent(resolvedDescriptors::addLast);
}
return resolvedDescriptors;
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class JavaElementsResolver method logMultipleTestDescriptorsForSingleElement.
private void logMultipleTestDescriptorsForSingleElement(AnnotatedElement element, Set<TestDescriptor> descriptors) {
if (descriptors.size() > 1 && element instanceof Method) {
Method method = (Method) element;
logger.warn(() -> 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(), descriptors.stream().map(d -> d.getClass().getName()).collect(toList())));
}
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesMethodSelectorForTwoMethodsOfSameClass.
@Test
void resolvesMethodSelectorForTwoMethodsOfSameClass() throws Exception {
Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectMethod(testClass, testClass.getMethod("failingTest")), selectMethod(testClass, testClass.getMethod("successfulTest"))).build();
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(runnerDescriptor, testClass);
List<TestDescriptor> testMethodDescriptors = new ArrayList<>(runnerDescriptor.getChildren());
assertThat(testMethodDescriptors).hasSize(2);
TestDescriptor failingTest = testMethodDescriptors.get(0);
assertTestMethodDescriptor(failingTest, testClass, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
TestDescriptor successfulTest = testMethodDescriptors.get(1);
assertTestMethodDescriptor(successfulTest, testClass, "successfulTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesPackageSelectorForJUnit4SamplesPackage.
@Test
void resolvesPackageSelectorForJUnit4SamplesPackage() {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectPackage(testClass.getPackage().getName())).build();
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
// @formatter:off
assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).contains(testClass.getName()).doesNotContain(PlainJUnit3TestCaseWithSingleTestWhichFails.class.getName());
// @formatter:on
}
Aggregations