dimanche 4 décembre 2016

Why reflections doesn't want to load my test classes?

I am using Reflections in Java :

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>

I can load every classes except my test classes.

List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());

Reflections reflections = new Reflections(new ConfigurationBuilder()
    .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
    .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))));

And I am using this method :

Set<Class<?>> allClasses = reflections.getSubTypesOf(Object.class);

My test classes are at the same location than the other classes (in src/main/java)

I think that it is on account of the framework. I think the Reflections don't find the JUnit, so, it can't load the class. Can I have give a classpath to Reflections ??





Aucun commentaire:

Enregistrer un commentaire