TypeNotPresentExceptionProxy

gan*_*sta 51 java junit exception surefire maven

从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)
Run Code Online (Sandbox Code Playgroud)

JUnit4TestChecker,第64行看起来像这样:

Annotation runWithAnnotation = testClass.getAnnotation( runWith );
Run Code Online (Sandbox Code Playgroud)

所以Surefire检查@RunWith注释以确保其类型有效.我们的测试使用Spring,所以@RunWith在我们的测试类中看起来像这样:

@RunWith(SpringJUnit4ClassRunner.class)
Run Code Online (Sandbox Code Playgroud)

似乎Surefire没有找到这个SpringJUnit4ClassRunner班级.我不确定为什么因为在Surefire 2.6下,测试运行良好.

有任何想法吗?

Use*_*F40 2

运行 mvn dependency:resolve

排除可能潜入的任何 3.x 版本的 JUnit。

确保没有 TestNG 依赖项,如果有,它将加载 TestNG 注释,而不是您需要的 JUnit 注释。