Android:更新mockito版本后单元测试失败

时间:2021-06-22 18:05:36

标签: android unit-testing mockito powermock

我有以下测试依赖

testImplementation "org.mockito:mockito-core:3.10.0"
testImplementation "org.powermock:powermock-module-junit4:$powerMockitoVersion"
testImplementation "org.powermock:powermock-api-mockito2:$powerMockitoVersion"
testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockitoVersion"
testImplementation "org.powermock:powermock-classloading-xstream:$powerMockitoVersion"
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'

powerMockitoVersion = 2.0.5

将 mockito 更新到 3.10.0 导致测试用例失败并出现错误

org.mockito.exceptions.misusing.NotAMockException:参数应该是一个模拟,但是是:class java.lang.Class

使用 powermock 的测试用例会发生这种情况。我尝试使用 mockito.mock-maker-class=mock-maker-inline 添加 org.powermock.extensions.configurations/configuration.properties,但这并没有解决问题。

我已经有了带有 mock-maker-inline 的 mockito-extensions/org.mockito.plugins.MockMaker 如果我删除此文件,则 NotAMockException 失败的测试用例会通过,但其他一些测试用例失败,原因是 Cannot mock/spy class com.cvent.leadcap.ui.dashboard.controller.DashboardControllerImpl Mockito 不能模拟/间谍,因为

这个怎么解决。 mockito 和 powermock 版本有没有不兼容的地方

0 个答案:

没有答案