use of org.junit.platform.engine.discovery.ClasspathRootSelector in project junit5 by junit-team.
the class DiscoveryRequestCreatorTests method convertsScanClasspathOptionWithExplicitRootDirectories.
@Test
void convertsScanClasspathOptionWithExplicitRootDirectories() {
options.setScanClasspath(true);
options.setSelectedClasspathEntries(asList(Paths.get("."), Paths.get("..")));
LauncherDiscoveryRequest request = convert();
List<ClasspathRootSelector> classpathRootSelectors = request.getSelectorsByType(ClasspathRootSelector.class);
// @formatter:off
assertThat(classpathRootSelectors).extracting(ClasspathRootSelector::getClasspathRoot).containsExactly(new File(".").toURI(), new File("..").toURI());
// @formatter:on
}
use of org.junit.platform.engine.discovery.ClasspathRootSelector in project junit5 by junit-team.
the class DiscoveryRequestCreatorTests method convertsScanClasspathOptionWithAdditionalClasspathEntries.
@Test
void convertsScanClasspathOptionWithAdditionalClasspathEntries() {
options.setScanClasspath(true);
options.setAdditionalClasspathEntries(asList(Paths.get("."), Paths.get("..")));
LauncherDiscoveryRequest request = convert();
List<ClasspathRootSelector> classpathRootSelectors = request.getSelectorsByType(ClasspathRootSelector.class);
// @formatter:off
assertThat(classpathRootSelectors).extracting(ClasspathRootSelector::getClasspathRoot).contains(new File(".").toURI(), new File("..").toURI());
// @formatter:on
}
use of org.junit.platform.engine.discovery.ClasspathRootSelector in project junit5 by junit-team.
the class TestClassWithTemplate method classpathResolutionForJarFiles.
@Test
void classpathResolutionForJarFiles() throws Exception {
URL jarUrl = getClass().getResource("/jupiter-testjar.jar");
Path path = Paths.get(jarUrl.toURI());
List<ClasspathRootSelector> selectors = selectClasspathRoots(singleton(path));
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try (URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl })) {
Thread.currentThread().setContextClassLoader(classLoader);
resolver.resolveSelectors(request().selectors(selectors).build(), engineDescriptor);
//
assertThat(uniqueIds()).contains(//
uniqueIdForTopLevelClass("com.example.project.FirstTest")).contains(uniqueIdForTopLevelClass("com.example.project.SecondTest"));
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
use of org.junit.platform.engine.discovery.ClasspathRootSelector in project junit5 by junit-team.
the class DiscoveryRequestCreatorTests method convertsScanClasspathOptionWithoutExplicitRootDirectories.
@Test
void convertsScanClasspathOptionWithoutExplicitRootDirectories() {
options.setScanClasspath(true);
LauncherDiscoveryRequest request = convert();
List<ClasspathRootSelector> classpathRootSelectors = request.getSelectorsByType(ClasspathRootSelector.class);
// @formatter:off
assertThat(classpathRootSelectors).extracting(ClasspathRootSelector::getClasspathRoot).hasAtLeastOneElementOfType(URI.class).doesNotContainNull();
// @formatter:on
}
use of org.junit.platform.engine.discovery.ClasspathRootSelector in project junit5 by junit-team.
the class TestClassWithTemplate method classpathResolution.
@Test
void classpathResolution() throws Exception {
Path classpath = Paths.get(DiscoverySelectorResolverTests.class.getProtectionDomain().getCodeSource().getLocation().toURI());
List<ClasspathRootSelector> selectors = selectClasspathRoots(singleton(classpath));
resolver.resolveSelectors(request().selectors(selectors).build(), engineDescriptor);
// 150 is completely arbitrary. The actual number is likely much higher.
//
assertThat(engineDescriptor.getDescendants().size()).describedAs(//
"Too few test descriptors in classpath").isGreaterThan(150);
List<UniqueId> uniqueIds = uniqueIds();
//
assertThat(uniqueIds).describedAs(//
"Failed to pick up DefaultPackageTestCase via classpath scanning").contains(uniqueIdForClass(ReflectionUtils.loadClass("DefaultPackageTestCase").get()));
assertThat(uniqueIds).contains(uniqueIdForClass(Class1WithTestCases.class));
assertThat(uniqueIds).contains(uniqueIdForMethod(Class1WithTestCases.class, "test1()"));
assertThat(uniqueIds).contains(uniqueIdForClass(Class2WithTestCases.class));
assertThat(uniqueIds).contains(uniqueIdForMethod(Class2WithTestCases.class, "test2()"));
assertThat(uniqueIds).contains(uniqueIdForMethod(ClassWithStaticInnerTestCases.ShouldBeDiscovered.class, "test1()"));
}
Aggregations