Search in sources :

Example 36 with TestDescriptor

use of org.junit.platform.engine.TestDescriptor in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithClasspathResourceSelectorAndFilePosition.

@Test
void resolveRequestWithClasspathResourceSelectorAndFilePosition() {
    String feature = "io/cucumber/junit/platform/engine/rule.feature";
    FilePosition line = FilePosition.from(5);
    DiscoverySelector resource = selectClasspathResource(feature, line);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(1L, testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).count());
}
Also used : FilePosition(org.junit.platform.engine.discovery.FilePosition) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 37 with TestDescriptor

use of org.junit.platform.engine.TestDescriptor in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithFileSelectorAndPosition.

@Test
void resolveRequestWithFileSelectorAndPosition() {
    String feature = "src/test/resources/io/cucumber/junit/platform/engine/rule.feature";
    FilePosition line = FilePosition.from(5);
    DiscoverySelector resource = selectFile(feature, line);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(1L, testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).count());
}
Also used : FilePosition(org.junit.platform.engine.discovery.FilePosition) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 38 with TestDescriptor

use of org.junit.platform.engine.TestDescriptor in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithClasspathResourceSelectorAndFilePositionOfContainer.

@Test
void resolveRequestWithClasspathResourceSelectorAndFilePositionOfContainer() {
    String feature = "io/cucumber/junit/platform/engine/rule.feature";
    FilePosition line = FilePosition.from(3);
    DiscoverySelector resource = selectClasspathResource(feature, line);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(2L, testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).count());
}
Also used : FilePosition(org.junit.platform.engine.discovery.FilePosition) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 39 with TestDescriptor

use of org.junit.platform.engine.TestDescriptor in project graylog2-server by Graylog2.

the class ContainerMatrixMethodSelectorResolver method resolve.

private Resolution resolve(Context context, List<Class<?>> enclosingClasses, Class<?> testClass, Supplier<Method> methodSupplier) {
    if (!testClassPredicate.test(testClass)) {
        return unresolved();
    }
    Method method = methodSupplier.get();
    // @formatter:off
    Set<Match> matches = Arrays.stream(ContainerMatrixMethodSelectorResolver.MethodType.values()).map(methodType -> methodType.resolve(enclosingClasses, testClass, method, context, configuration)).filter(Optional::isPresent).map(Optional::get).map(testDescriptor -> Match.exact(testDescriptor, expansionCallback(testDescriptor))).collect(toSet());
    // @formatter:on
    if (matches.size() > 1) {
        logger.warn(() -> {
            Stream<TestDescriptor> testDescriptors = matches.stream().map(Match::getTestDescriptor);
            return f("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 : IsContainerMatrixTest(org.junit.jupiter.engine.discovery.predicates.IsContainerMatrixTest) Arrays(java.util.Arrays) IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) 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) 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) LinkedHashSet(java.util.LinkedHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) Collections.emptySet(java.util.Collections.emptySet) StringUtils.f(org.graylog2.shared.utilities.StringUtils.f) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) Logger(org.junit.platform.commons.logging.Logger) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) UniqueId(org.junit.platform.engine.UniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) ClassUtils(org.junit.platform.commons.util.ClassUtils) NestedMethodSelector(org.junit.platform.engine.discovery.NestedMethodSelector) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) 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) Method(java.lang.reflect.Method) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 40 with TestDescriptor

use of org.junit.platform.engine.TestDescriptor in project junit5 by junit-team.

the class AtypicalJvmMethodNameTests method kotlinTestWithMethodNameContainingSpecialCharacters.

@Test
void kotlinTestWithMethodNameContainingSpecialCharacters() {
    EngineExecutionResults executionResults = executeTestsForClass(ArbitraryNamingKotlinTestCase.class);
    assertThat(executionResults.testEvents().started().count()).isEqualTo(2);
    TestDescriptor testDescriptor1 = executionResults.testEvents().succeeded().list().get(0).getTestDescriptor();
    assertAll(// 
    () -> assertEquals(METHOD_NAME + "()", testDescriptor1.getDisplayName()), () -> assertEquals(METHOD_NAME + "()", testDescriptor1.getLegacyReportingName()));
    TestDescriptor testDescriptor2 = executionResults.testEvents().succeeded().list().get(1).getTestDescriptor();
    assertAll(// 
    () -> assertEquals("test name ends with parentheses()()", testDescriptor2.getDisplayName()), () -> assertEquals("test name ends with parentheses()()", testDescriptor2.getLegacyReportingName()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) TestDescriptor(org.junit.platform.engine.TestDescriptor) 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