Search in sources :

Example 41 with TestDescriptor

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
}
Also used : Events(org.junit.platform.testkit.engine.Events) TestDescriptor(org.junit.platform.engine.TestDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 42 with TestDescriptor

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);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 43 with TestDescriptor

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();
}
Also used : TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 44 with TestDescriptor

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

Example 45 with TestDescriptor

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);
}
Also used : Arrays(java.util.Arrays) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) IsTestClassWithTests(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests) BiFunction(java.util.function.BiFunction) IterationSelector(org.junit.platform.engine.discovery.IterationSelector) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Supplier(java.util.function.Supplier) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass) Filterable(org.junit.jupiter.engine.descriptor.Filterable) IsTestTemplateMethod(org.junit.jupiter.engine.discovery.predicates.IsTestTemplateMethod) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) Resolution.unresolved(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.unresolved) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) LinkedHashSet(java.util.LinkedHashSet) TestTemplateTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) Collections.emptySet(java.util.Collections.emptySet) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) Logger(org.junit.platform.commons.logging.Logger) Set(java.util.Set) TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) UniqueId(org.junit.platform.engine.UniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ClassUtils(org.junit.platform.commons.util.ClassUtils) NestedMethodSelector(org.junit.platform.engine.discovery.NestedMethodSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Stream(java.util.stream.Stream) IsTestFactoryMethod(org.junit.jupiter.engine.discovery.predicates.IsTestFactoryMethod) IsTestMethod(org.junit.jupiter.engine.discovery.predicates.IsTestMethod) Resolution.matches(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.matches) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) SelectorResolver(org.junit.platform.engine.support.discovery.SelectorResolver) Optional(java.util.Optional) IsTestTemplateMethod(org.junit.jupiter.engine.discovery.predicates.IsTestTemplateMethod) Method(java.lang.reflect.Method) IsTestFactoryMethod(org.junit.jupiter.engine.discovery.predicates.IsTestFactoryMethod) IsTestMethod(org.junit.jupiter.engine.discovery.predicates.IsTestMethod) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) TestTemplateTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

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