如何让Powermock与Dexmaker合作

Som*_*ent 8 java android mockito powermock dexmaker

我正在尝试使用以下build.gradle配置将Powermock作为我的Android测试的依赖项:

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

但是,编译器抱怨说

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

展望罐子结构,我注意到Dexmaker和Powermock都宣布MockMakermockito-extensions

IMG

什么是MockMaker?他们有什么不同?最重要的问题是:是否有可能让Powermock与Dexmaker很好地合作?

提前致谢.任何帮助将不胜感激.

Jes*_*son 10

MockMaker是一个将dexmaker与Mockito集成在一起的胶水模块.它为Mockito创建了使用Dalvik .dex文件而不是JVM .class文件生成具体类所必需的.

Powermock可能会与Dexmaker合作,但高级Powermock功能不太可行.特别是,Powermock 宣传了这个:

PowerMock使用自定义类加载器和字节码操作来实现静态方法,构造函数,最终类和方法,私有方法,静态初始化程序的删除等的模拟.

自定义类加载器不太可能在dalvikvm上运行.