首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoSuchMethodError在Hamcrest中的安卓单元测试

NoSuchMethodError在Hamcrest中的安卓单元测试
EN

Stack Overflow用户
提问于 2015-08-27 20:55:40
回答 1查看 683关注 0票数 0

我正试图在我的Android单元测试中使用ExpectedException @ JUnit4规则,但是java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch的测试失败了。

其他问题表明,我在我的其他库中有一个旧版本的Hamcrest,但情况似乎并非如此。我将Hamcrest排除在所有其他库之外,并明确包括Hamcrest 1.3。

代码语言:javascript
复制
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile ('junit:junit:4.12') {
    exclude module: 'hamcrest-core'
}
testCompile ('org.mockito:mockito-core:1.10.19') {
    exclude module: 'hamcrest-core'
}
testCompile ('org.powermock:powermock-api-mockito:1.6.2') {
    exclude module: 'hamcrest-core'
    exclude module: 'objenesis'
}
testCompile ('org.powermock:powermock-module-junit4:1.6.2') {
    exclude module: 'hamcrest-core'
    exclude module: 'objenesis'
}

这是依赖关系图。

代码语言:javascript
复制
+--- org.hamcrest:hamcrest-core:1.3
+--- junit:junit:4.12
+--- org.mockito:mockito-core:1.10.19
|    \--- org.objenesis:objenesis:2.1
+--- org.powermock:powermock-api-mockito:1.6.2
|    +--- org.mockito:mockito-all:1.10.19
|    \--- org.powermock:powermock-api-support:1.6.2
|         +--- org.powermock:powermock-core:1.6.2
|         |    +--- org.powermock:powermock-reflect:1.6.2
|         |    \--- org.javassist:javassist:3.19.0-GA
|         \--- org.powermock:powermock-reflect:1.6.2
\--- org.powermock:powermock-module-junit4:1.6.2
     +--- junit:junit:4.12
     \--- org.powermock:powermock-module-junit4-common:1.6.2
          +--- junit:junit:4.4 -> 4.12
          +--- org.powermock:powermock-core:1.6.2 (*)
          \--- org.powermock:powermock-reflect:1.6.2

如果我没有将Hamcrest作为显式依赖项包括在内,那么我将得到一个ClassNotFoundException: org.hamcrest.TypeSafeMatcher,因此没有其他任何东西包括它。

我使用AndroidStudio1.3.2和Gradle插件1.2.3。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-28 17:54:51

清除Android中的缓存(文件->失效缓存/重新启动)修复了我的问题。不需要将Hamcrest排除在JUnit和Mockito之外。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32259298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档