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
}
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");
}
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));
}
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));
}
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);
}
}
Aggregations