我试图与Mockito和PowerMockito进行单元测试,但它会抛出:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter
每当我尝试运行测试时。这些是我的依赖:
testCompile 'org.mockito:mockito-core:2.8.9'
testCompile 'org.powermock:powermock-api-mockito2:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.7.4'
有谁知道如何修复它?
答案 0 :(得分:1)
您似乎正在尝试使用不兼容的版本。
根据此table,您需要使用Powermock的1.7.x
版本才能与您的Mockito版本2.8.9
兼容。
答案 1 :(得分:0)
在您的external-dependencies.xml
-
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-support</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-common</artifactId>
<version>1.5.6</version>
</dependency>
powermock 1.5.6
的{{1}}问题-需要junit 4.12
:在类中找不到字段'fTestClass'
powermock
1.6.1 :: org.powermock.reflect.exceptions.FieldNotFoundException
需要更多当前的 mockito ::在类层次结构中找不到与添加的名称匹配的方法
org.junit.internal.runners.MethodValidator powermock 1.6.1
接口。
切换到org.mockito.internal.util.MockitoSpy
,同时将模拟升级到powermock 1.6.2
::结果1.10.8
:
java.lang.NoClassDefFoundError
切换到org/mockito/internal/creation/util/MockitoMethodProxy
和mockito-core 1.10.19