mid*_*ght 44 android powermock gradle
我找不到有关如何使用Android Studio/Gradle设置powermock的任何信息.我尝试过的所有内容都会导致构建异常.
任何人都可以展示出正确的方法吗?
谢谢.
Bha*_*gav 56
我发帖是为了帮助未来的读者,你需要在AS中为powermock添加这些依赖项
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock-api-mockito:1.6.2'
testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.2'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.2'
testCompile 'org.powermock:powermock-module-junit4:1.6.2'
Run Code Online (Sandbox Code Playgroud)
plá*_*omo 24
将以下行添加到依赖项{}块:
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.5'
Run Code Online (Sandbox Code Playgroud)
如果您想使用PowerMockito,请添加以下行:
testCompile 'org.powermock:powermock-api-mockito:1.6.5'
Run Code Online (Sandbox Code Playgroud)
在构建脚本中,添加以下内容:
sourceSets {
unitTest {
java.srcDir file('*your test directory*') //for example: tests/java
}
}
android {
sourceSets {
instrumentTest.setRoot('*your root test directory*') //for example: tests
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.powermock:powermock-mockito-release-full:1.4.9'
}
Run Code Online (Sandbox Code Playgroud)
然后,从命令行执行 gradle unitTest。
希望有效。如果没有,请发布命令行的输出。
如果您想使用Mockito的最新版本,可以使用类似的东西,该东西是从Mockito 2 Powermock docs改编而来的。确保确保为给定的Mockito版本使用正确的PowerMock版本。
...
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:2.4.0"
testCompile 'org.powermock:powermock-module-junit4:1.7.0RC2',
'org.powermock:powermock-api-mockito2:1.7.0RC2'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24459 次 |
| 最近记录: |