Search in sources :

Example 96 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class VintageTestEngineDiscoveryTests method resolvesSimpleJUnit4TestClass.

@Test
void resolvesSimpleJUnit4TestClass() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.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, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 97 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class VintageTestEngineDiscoveryTests method resolvesTestSourceForParameterizedTests.

@Test
void resolvesTestSourceForParameterizedTests() throws Exception {
    Class<?> testClass = ParameterizedTestCase.class;
    LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build();
    TestDescriptor engineDescriptor = discoverTests(request);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    TestDescriptor fooParentDescriptor = findChildByDisplayName(runnerDescriptor, "[foo]");
    assertTrue(fooParentDescriptor.isContainer());
    assertFalse(fooParentDescriptor.isTest());
    assertThat(fooParentDescriptor.getSource()).isEmpty();
    TestDescriptor testMethodDescriptor = getOnlyElement(fooParentDescriptor.getChildren());
    assertEquals("test[foo]", testMethodDescriptor.getDisplayName());
    assertTrue(testMethodDescriptor.isTest());
    assertFalse(testMethodDescriptor.isContainer());
    assertMethodSource(testClass.getMethod("test"), testMethodDescriptor);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ParameterizedTestCase(org.junit.vintage.engine.samples.junit4.ParameterizedTestCase) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 98 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class VintageTestEngineDiscoveryTests method resolvesClassForMethodSelectorForClassWithNonFilterableRunner.

@Test
void resolvesClassForMethodSelectorForClassWithNonFilterableRunner() {
    Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
    // @formatter:off
    LauncherDiscoveryRequest request = request().selectors(selectUniqueId(VintageUniqueIdBuilder.uniqueIdForMethod(testClass, "Test #0"))).build();
    // @formatter:on
    TestDescriptor engineDescriptor = discoverTests(request);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertEquals(testClass.getName(), runnerDescriptor.getDisplayName());
    assertEquals(VintageUniqueIdBuilder.uniqueIdForClass(testClass), runnerDescriptor.getUniqueId());
    assertThat(runnerDescriptor.getChildren()).isNotEmpty();
}
Also used : JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 99 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest 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 100 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest 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)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)158 Test (org.junit.jupiter.api.Test)141 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)74 TestDescriptor (org.junit.platform.engine.TestDescriptor)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)33 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)11 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)11 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)11 Method (java.lang.reflect.Method)9 Launcher (org.junit.platform.launcher.Launcher)9 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)5 Path (java.nio.file.Path)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4 TestIdentifier (org.junit.platform.launcher.TestIdentifier)4 TestPlan (org.junit.platform.launcher.TestPlan)4