Pik*_*ing 8 junit android mockito gradle android-espresso
我有一个Android项目,使用Mockito,Hamcrest和Espresso来帮助测试.
不管我用摇篮尝试构建文件,我得到NoSuchMethodError的org.hamcrest.Matcher.anyOf,当我尝试做后运行我的测试gradle androidTestCompile.
这是我目前的配置:
dependencies {
compile project(':GameCore')
androidTestCompile files(
'libs/espresso-1.1.jar',
'libs/testrunner-1.1.jar',
'libs/testrunner-runtime-1.1.jar'
)
androidTestCompile(
'junit:junit:4.11',
'org.mockito:mockito-core:1.10.0',
'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'com.google.dexmaker:dexmaker:1.0',
'com.google.dexmaker:dexmaker-mockito:1.0',
'org.hamcrest:hamcrest-core:1.3',
'org.hamcrest:hamcrest-library:1.3'
)
Run Code Online (Sandbox Code Playgroud)
我已经尝试重写Mockito和JUnit要求以排除Hamcrest,如下所示:
androidTestCompile('junit:junit:4.11') {
exclude group: 'org.hamcrest'
}
Run Code Online (Sandbox Code Playgroud)
但这没有任何区别.
该GameCore项目是一个纯Java项目.它也依赖于JUnit和Mockito,但正如它们被指定的那样testCompile,我认为它们不应该干扰它们.
gradle dependencies这个'androidTestCompile`模块的输出是:
+--- junit:junit:4.11
| \--- org.hamcrest:hamcrest-core:1.3
+--- org.mockito:mockito-core:1.10.0
| +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
| \--- org.objenesis:objenesis:2.1
+--- com.google.guava:guava:14.0.1
+--- com.squareup.dagger:dagger:1.1.0
| \--- javax.inject:javax.inject:1
+--- com.google.dexmaker:dexmaker:1.0
+--- com.google.dexmaker:dexmaker-mockito:1.0
| +--- com.google.dexmaker:dexmaker:1.0
| \--- org.mockito:mockito-core:1.9.5 -> 1.10.0 (*)
+--- org.hamcrest:hamcrest-core:1.3
\--- org.hamcrest:hamcrest-library:1.3
\--- org.hamcrest:hamcrest-core:1.3
Run Code Online (Sandbox Code Playgroud)
编辑
进一步调查了这个问题后,我发现espresso需要Hamcrest 1.1,但我也使用了assertThat,它位于Hamcrest 1.3中.Hamcrest 1.3没有espresso使用的anyOf方法.所以我想我被困了:)
我意识到这assertThat是在 Hamcrest 1.1 中,它只是在hamcrest-integration而不是hamcrest-core. 我更改了我的构建文件,现在一切正常:
androidTestCompile files(
'libs/espresso-1.1.jar',
'libs/testrunner-1.1.jar',
'libs/testrunner-runtime-1.1.jar'
)
androidTestCompile(
'org.mockito:mockito-core:1.9.5',
'com.google.dexmaker:dexmaker-mockito:1.0',
'com.google.dexmaker:dexmaker:1.0',
'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-library:1.1'
)
Run Code Online (Sandbox Code Playgroud)
我尝试使用espresso-1.1-bundled.jar但导致 dex 错误,因为引入了 Hamcrest 1.1 的两个副本,所以我不得不将它从一堆依赖项中排除。
| 归档时间: |
|
| 查看次数: |
12397 次 |
| 最近记录: |