我知道解决方案是以某种方式确保 Junit 在 hamcrest 之后加载。我有一个 intellij 项目,我在其中设置了一个外部库,其中包含 JUnit、JMock 和 hamcrest。我怎样才能确保这个错误不会出现
最佳答案
- junit:junit:4.11 取代了之前的 junit:junit-dep
- JUnit 4.11 包含 org.hamcrest:hamcrest-core:1.3 jar 作为依赖项
- 要在测试中使用显式 Hamcrest 匹配器,请包含 org.hamcrest:hamcrest-library:1.3。
- org.mockito:mockito-all:1.9.x - 包括 Hamcrest 的旧版本,不是作为依赖而是包装在它的 jar 中。这是罪魁祸首。 ( https://code.google.com/p/mockito/issues/detail?id=459 )
- 将 org.hamcrest:hamcrest-core:1.3 放在所有测试依赖项之前
- 使用 Maven 的 dependencyManagement 部分来控制 junit、hamcrest 和 mockito jar 的所有传递版本。例如 spring-integration-test 可传递地包含 mockito-all:1.9.0。
关于java - JMock- java.lang.NoSuchMethodError : org. hamcrest.Matcher.describeMismatch() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12070514/