Search in sources :

Example 81 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesMethodSelectorForSingleMethod.

@Test
void resolvesMethodSelectorForSingleMethod() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequest discoveryRequest = request().selectors(selectMethod(testClass, testClass.getMethod("failingTest"))).build();
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
    assertTestMethodDescriptor(childDescriptor, testClass, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) 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 82 with TestDescriptor

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

the class RunListenerAdapter method registerDynamicTestDescriptor.

private VintageTestDescriptor registerDynamicTestDescriptor(Description description) {
    // workaround for dynamic children as used by Spock's Runner
    TestDescriptor parent = findParent(description);
    UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description));
    VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description);
    parent.addChild(dynamicDescriptor);
    testRun.registerDynamicTest(dynamicDescriptor);
    dynamicTestRegistered(dynamicDescriptor);
    return dynamicDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 83 with TestDescriptor

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

the class VintageDiscovererTests method classNameFilterExcludesClass.

@Test
void classNameFilterExcludesClass() {
    // @formatter:off
    EngineDiscoveryRequest request = request().selectors(selectClass(Foo.class), selectClass(Bar.class)).filters(ClassNameFilter.includeClassNamePatterns(".*Foo")).build();
    // @formatter:on
    VintageDiscoverer discoverer = new VintageDiscoverer();
    TestDescriptor testDescriptor = discoverer.discover(request, engineId());
    assertThat(testDescriptor.getChildren()).hasSize(1);
    assertThat(getOnlyElement(testDescriptor.getChildren()).getUniqueId().toString()).contains(Foo.class.getName());
}
Also used : EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 84 with TestDescriptor

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

the class DiscoveryFilterApplierTests method packageNameFilterInclude_nonMatchingPackagesAreExcluded.

@Test
void packageNameFilterInclude_nonMatchingPackagesAreExcluded() {
    // @formatter:off
    TestDescriptor engineDescriptor = engineDescriptor().with(classTestDescriptor("matching", MatchingClass.class)).build();
    // @formatter:on
    applyClassNamePredicate(engineDescriptor, includePackageNames("org.junit.jupiter.engine.unknown"));
    assertThat(engineDescriptor.getDescendants()).isEmpty();
}
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 85 with TestDescriptor

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

the class DiscoveryFilterApplierTests method packageNameFilterExclude_nonMatchingPackagesAreIncluded.

@Test
void packageNameFilterExclude_nonMatchingPackagesAreIncluded() {
    // @formatter:off
    TestDescriptor engineDescriptor = engineDescriptor().with(classTestDescriptor("matching", MatchingClass.class)).build();
    applyClassNamePredicate(engineDescriptor, excludePackageNames("org.junit.jupiter.engine.unknown"));
    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)

Aggregations

TestDescriptor (org.junit.platform.engine.TestDescriptor)120 Test (org.junit.jupiter.api.Test)96 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)31 UniqueId (org.junit.platform.engine.UniqueId)22 TestPlan (org.junit.platform.launcher.TestPlan)14 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)12 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)10 Optional (java.util.Optional)9 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)9 TestIdentifier (org.junit.platform.launcher.TestIdentifier)9 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)9 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)8 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)8 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)8 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 List (java.util.List)7 DynamicTest (org.junit.jupiter.api.DynamicTest)7