I am trying to discover JUnit 5 tests with the help of LauncherDiscoveryRequest
as described in the user guide. The code I am using looks as follows:
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.filters(includeClassNamePatterns(".*"))
.build();
TestPlan plan = LauncherFactory.create().discover(request);
for (TestIdentifier root : plan.getRoots()) {
System.out.println("Root: " + root.toString());
for (TestIdentifier test : plan.getChildren(root)) {
System.out.println("Found test: " + test.toString());
}
}
Does LauncherDiscoveryRequestBuilder
only auto-discover tests on the classpath of the JVM running this code? I tried using the methods DiscoverySelectors.selectClasspathRoots
and DiscoverySelectors.selectClasspathResource
as selectors to provide root directories to be searched for test classes. However, I wasn't able to discover any tests. Do the parameters for selectClasspathRoots
and selectClasspathResource
have to point to the root directory containing the class files organized by package or do you provide the full path to each test class file?
I tried the following where /some/dir
represents the root directory containing test class files:
File classesDir = new File("/some/dir");
LauncherDiscoveryRequestBuilder.request()
.selectors(selectClasspathRoots(Collections.singleton(Paths.get(classesDir.toURI()))))
.build();
I had a look at LauncherDiscoveryRequestBuilderTests.java
but it wasn't very useful in figuring out why my example code doesn't work. How do I best diagnose the issue?
I am using the following dependencies:
org.junit.platform:junit-platform-engine:1.0.0-M3
org.junit.platform:junit-platform-launcher:1.0.0-M3