Search in sources :

Example 11 with TestDescriptor

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
}
Also used : TestDescriptorBuilder.classTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.classTestDescriptor) TestDescriptorBuilder.nestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.nestedClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with TestDescriptor

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;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Optional(java.util.Optional) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Segment(org.junit.platform.engine.UniqueId.Segment) LinkedList(java.util.LinkedList)

Example 13 with TestDescriptor

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())));
    }
}
Also used : ReflectionUtils.findMethods(org.junit.platform.commons.util.ReflectionUtils.findMethods) Deque(java.util.Deque) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) HashSet(java.util.HashSet) Filterable(org.junit.jupiter.engine.descriptor.Filterable) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) LinkedList(java.util.LinkedList) ReflectionUtils.findNestedClasses(org.junit.platform.commons.util.ReflectionUtils.findNestedClasses) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) LinkedHashSet(java.util.LinkedHashSet) Logger(org.junit.platform.commons.logging.Logger) Collection(java.util.Collection) Set(java.util.Set) UniqueId(org.junit.platform.engine.UniqueId) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) String.format(java.lang.String.format) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Segment(org.junit.platform.engine.UniqueId.Segment) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) Collections(java.util.Collections) IsInnerClass(org.junit.jupiter.engine.discovery.predicates.IsInnerClass) AnnotatedElement(java.lang.reflect.AnnotatedElement) Method(java.lang.reflect.Method)

Example 14 with TestDescriptor

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));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ArrayList(java.util.ArrayList) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 15 with TestDescriptor

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
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) PlainJUnit3TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit3.PlainJUnit3TestCaseWithSingleTestWhichFails) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Aggregations

TestDescriptor (org.junit.platform.engine.TestDescriptor)143 Test (org.junit.jupiter.api.Test)103 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)58 UniqueId (org.junit.platform.engine.UniqueId)33 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)31 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)19 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)17 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)14 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Set (java.util.Set)11 DynamicTest (org.junit.jupiter.api.DynamicTest)11 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)11 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)11 Optional (java.util.Optional)10 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)9 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)9