从Surefire 2.6升级到Surefire 2.13时,我在运行单元测试时得到TypeNotPresentExceptionProxy
。
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行看起来像这样:
Annotation runWithAnnotation = testClass.getAnnotation( runWith );
所以Surefire检查@RunWith
注释以确保其类型有效。我们的测试使用Spring,因此@RunWith
在我们的测试类中看起来像这样:
@RunWith(SpringJUnit4ClassRunner.class)
似乎Surefire没有找到SpringJUnit4ClassRunner
类。我不确定为什么因为在Surefire 2.6下,测试运行良好。
有什么想法吗?
答案 0 :(得分:2)
运行mvn依赖:解决
排除可能已经悄悄进入的任何3.x版本的JUnit。
确保没有TestNG依赖项,如果有它将加载TestNG注释而不是您需要的JUnit注释。