问题描述
从Surefire 2.6升级到Surefire 2.13时,运行单元测试时得到TypeNotPresentExceptionProxy
.
When upgrading from Surefire 2.6 to Surefire 2.13, I get a TypeNotPresentExceptionProxy
when running my unit tests.
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
at java.lang.Class.getAnnotation(Class.java:3029)
at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.isValidJUnit4Test(JUnit4TestChecker.java:64)
在JUnit4TestChecker
中,第64行如下所示:
In JUnit4TestChecker
, line 64 looks like this:
Annotation runWithAnnotation = testClass.getAnnotation( runWith );
因此Surefire检查@RunWith
批注以确保其类型有效.我们的测试使用Spring,因此@RunWith
在我们的测试类中看起来像这样:
So Surefire inspects the @RunWith
annotation to make sure its type is valid. Our tests use Spring, so @RunWith
looks like this in our test classes:
@RunWith(SpringJUnit4ClassRunner.class)
Surefire似乎没有找到SpringJUnit4ClassRunner
类.我不确定为什么在Surefire 2.6下可以正常运行测试.
It seems like Surefire isn't finding the SpringJUnit4ClassRunner
class. I'm not sure why since under Surefire 2.6, the tests run fine.
有什么想法吗?
推荐答案
运行mvn依赖项:解决
Run mvn dependency:resolve
排除任何可能已潜入的JUnit 3.x版本.
Exclude any 3.x version of JUnit that may have crept in.
确保没有TestNG依赖项,如果有,它将加载TestNG注释,而不是您需要的JUnit注释.
Make sure there are no TestNG dependencies, if there are it will load TestNG annotations and not the JUnit ones you need.
这篇关于TypeNotPresentExceptionProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!