我正在尝试合并 Powermock作为我的 Android 测试的依赖项,使用以下 build.gradle 配置:
dependencies{
compile 'com.android.support:appcompat-v7:21.0.+'
androidTestCompile('org.mockito:mockito-core:1.9.5')
androidTestCompile('com.google.dexmaker:dexmaker:1.2')
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.2')
androidTestCompile('org.powermock:powermock-module-junit4:1.5.5') {
exclude module: 'junit'
}
androidTestCompile('org.powermock:powermock-api-mockito:1.5.5') {
exclude module: 'mockito-all'
}
}
然而,编译器提示
Error:Gradle: Execution failed for task ':app:packageDebugTest'.
> Duplicate files copied in APK mockito-extensions/org.mockito.plugins.MockMaker
File 1: ~/.gradle/caches/modules-2/files-2.1/com.google.dexmaker/dexmaker-mockito/1.2/b99884a4c6ef6335ba376f79aa79632b2421c17c/dexmaker-mockito-1.2.jar
File 2: ~/.gradle/caches/modules-2/files-2.1/com.google.dexmaker/dexmaker-mockito/1.2/b99884a4c6ef6335ba376f79aa79632b2421c17c/dexmaker-mockito-1.2.jar
查看 jar 结构,我注意到 Dexmaker 和 Powermock 都在 mockito-extensions
中声明了一个 MockMaker
什么是 MockMaker?它们有何不同? 最重要的问题是:是否有可能让 Powermock 与 Dexmaker 很好地协同工作?
提前致谢。任何帮助将不胜感激。
最佳答案
MockMaker 是一个将 dexmaker 与 Mockito 集成的胶水模块。它执行 Mockito 使用 Dalvik .dex 文件而不是 JVM .class 文件生成具体类所需的操作。
Powermock 有可能与 Dexmaker 一起工作,但高级 Powermock 功能不太可能工作。特别是 Powermock advertises this :
PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more.
那个自定义类加载器不太可能在 dalvikvm 上工作。
关于java - 如何让 Powermock 与 Dexmaker 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27953270/