JUnit引入junit-4.12.jar,单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
版本问题:
JUnit 4.11
以上版本不再包含hamcrest
的依赖包
JUnit now uses the latest version of Hamcrest. Thus, you can use all the available matchers and benefit from an improved assertThat which will now print the mismatch description from the matcher when an assertion fails.
- junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get started quickly.
Starting with version 4.11, Hamcrest is no longer included in this jar.
- junit-dep.jar: Only includes the JUnit classes but not Hamcrest. Lets you use a different Hamcrest version.
解决方式:
- 回退到
junit-4.10.jar
- 添加
hamcrest-core-1.3.jar
-
- 既然用了
junit-4.12.jar
版本,那就再添加一个hamcrest-core-1.3.jar
吧
- 既然用了