Search in sources :

Example 76 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesApplyingClassNameFilters.

@Test
void resolvesApplyingClassNameFilters() throws Exception {
    Path root = getClasspathRoot(PlainJUnit4TestCaseWithSingleTestWhichFails.class);
    LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClasspathRoots(singleton(root))).filters(includeClassNamePatterns(".*JUnit4.*"), includeClassNamePatterns(".*Plain.*")).build();
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    // @formatter:off
    assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).contains(PlainJUnit4TestCaseWithSingleTestWhichFails.class.getName()).doesNotContain(JUnit4TestCaseWithOverloadedMethod.class.getName()).doesNotContain(PlainJUnit3TestCaseWithSingleTestWhichFails.class.getName());
// @formatter:on
}
Also used : Path(java.nio.file.Path) 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)

Example 77 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method usesCustomUniqueIdsWhenPresent.

@Test
void usesCustomUniqueIdsWhenPresent() {
    Class<?> testClass = JUnit4TestCaseWithRunnerWithCustomUniqueIds.class;
    LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build();
    TestDescriptor engineDescriptor = discoverTests(request);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
    UniqueId prefix = VintageUniqueIdBuilder.uniqueIdForClass(testClass);
    assertThat(childDescriptor.getUniqueId().toString()).startsWith(prefix.toString());
    String customUniqueIdValue = childDescriptor.getUniqueId().getSegments().get(2).getType();
    assertNotNull(Base64.getDecoder().decode(customUniqueIdValue.getBytes(StandardCharsets.UTF_8)), "is a valid Base64 encoding scheme");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) JUnit4TestCaseWithRunnerWithCustomUniqueIds(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithRunnerWithCustomUniqueIds) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 78 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesIgnoredJUnit4TestClass.

@Test
void resolvesIgnoredJUnit4TestClass() throws Exception {
    Class<?> testClass = IgnoredJUnit4TestCase.class;
    LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(testClass);
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    assertThat(runnerDescriptor.getChildren()).hasSize(2);
    List<? extends TestDescriptor> children = new ArrayList<>(runnerDescriptor.getChildren());
    assertTestMethodDescriptor(children.get(0), testClass, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
    assertTestMethodDescriptor(children.get(1), testClass, "succeedingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) IgnoredJUnit4TestCase(org.junit.vintage.engine.samples.junit4.IgnoredJUnit4TestCase) ArrayList(java.util.ArrayList) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 79 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesJUnit4TestClassWithCustomRunner.

@Test
void resolvesJUnit4TestClassWithCustomRunner() throws Exception {
    Class<?> testClass = SingleFailingTheoryTestCase.class;
    LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(testClass);
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
    assertTestMethodDescriptor(childDescriptor, testClass, "theory", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) SingleFailingTheoryTestCase(org.junit.vintage.engine.samples.junit4.SingleFailingTheoryTestCase) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 80 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesClasspathSelectorForJarFile.

@Test
void resolvesClasspathSelectorForJarFile() throws Exception {
    URL jarUrl = getClass().getResource("/vintage-testjar.jar");
    Path jarFile = Paths.get(jarUrl.toURI());
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try (URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl })) {
        Thread.currentThread().setContextClassLoader(classLoader);
        LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClasspathRoots(singleton(jarFile))).build();
        TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
        // @formatter:off
        assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).containsExactly("com.example.project.JUnit4Test");
    // @formatter:on
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
}
Also used : Path(java.nio.file.Path) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) TestDescriptor(org.junit.platform.engine.TestDescriptor) URL(java.net.URL) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) 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