Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow third parties to provide a custom ClasspathScanner implementation #3628

Open
yuuki3655 opened this issue Jan 4, 2024 · 3 comments
Open

Comments

@yuuki3655
Copy link

yuuki3655 commented Jan 4, 2024

The Jupiter and Vintage engines use org.junit.platform.commons.util.ClasspathScanner to discover test classes in the classpath. The ClasspathScanner scans directories and looks for class files. It works fine for a standard JVM process; however, it needs to be customized for a specific environment such as Android.

A possible solution for this is to make the ClasspathScanner an interface and load the implementation via the ServiceLoader mechanism.

public interface ClasspathScanner {
	static ClasspathScanner getInstance() {
		ServiceLoader<ClasspathScanner> serviceLoader = ServiceLoader.load(ClasspathScanner.class);
		for (ClasspathScanner scanner : serviceLoader) {
			return scanner;
		}
		return new DefaultClasspathScanner(ClassLoaderUtils::getDefaultClassLoader, ReflectionUtils::tryToLoadClass);
	}

	List<Class<?>> scanForClassesInPackage(String basePackageName, ClassFilter classFilter);

	List<Class<?>> scanForClassesInClasspathRoot(URI root, ClassFilter classFilter);
}

Then, we could provide the Android-specific implementation with androidx.test.internal.runner.ClassPathScanner, for example.

This change would make the Jupiter and Vintage engines work in Android.

@marcphilipp
Copy link
Member

Thanks for the proposal! It'd be awesome to get Jupiter and Vintage working out-of-the-box on Android. I'll discuss it with the team and will get back to you.

@sbrannen sbrannen changed the title Configurable ClasspathScanner Allow third parties to provide a custom ClasspathScanner implementation Jan 4, 2024
@sbrannen
Copy link
Member

sbrannen commented Jan 4, 2024

SGTM.

Let's put that interface in the org.junit.platform.commons.support.scanning package.

@marcphilipp
Copy link
Member

Team decision: Let's follow the proposal but wait for #3630 to be done first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants