简体   繁体   English

为什么反射不想加载我的测试类?

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

I am using Reflections in Java : 我在Java中使用Reflections:

<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) 我的测试类与其他类位于同一位置(在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. 我认为Reflections没有找到JUnit,因此,它无法加载类。 Can I have give a classpath to Reflections ?? 我可以给一个类路径到Reflections吗?

Not in target ? 不在目标? => Reflections doesn't see... =>思考没看到......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM