我知道解决方案是以某种方式确保 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 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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)