我正在尝试在我的项目中导入mockito,这是不可能的。我花了很多时间尝试......我正在使用Android Studio 3.0
我在gradle依赖项中有这个:
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:2.11.0"
testCompile "org.powermock:powermock-module-junit4:1.6.2"
testCompile "org.powermock:powermock-api-mockito:1.6.2"
但我无法在我的测试类中导入有关mockito的任何内容。
如果我将testCompile更改为
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:2.11.0"
androidTestCompile "org.powermock:powermock-module-junit4:1.6.2"
androidTestCompile "org.powermock:powermock-api-mockito:1.6.2"
我可以导入所有内容,但是当我尝试运行测试时,我在logcat中遇到了这个错误:
Error:Execution failed for task ':myproject:transformDexArchiveWithExternalLibsDexMergerForMyprojectDebugAndroidTest'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
一些帮助将是apreciate!
答案 0 :(得分:0)
您似乎正在使用不兼容的powermock和mockito版本。 基于compatibility table powermock-1.6.2与Mockito 1.10.x兼容。
尝试使用mockito 2.8.9和powermock 1.7.3。
不确定是否会出现这种情况,但是在运行测试时,您无论如何都会遇到问题。
答案 1 :(得分:0)
转到此网站... http://gradleplease.appspot.com/并搜索您想要的库
并且必须在build.gradle中添加mavan(Project:xxx)
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}