junit 单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
junit 单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing1.环境信息jdk :jdk1.8junit版本:4.12jar包引用情况:没有使用maven、gradle等,只单独引用了junit-4.12.jar文件报错信息:java.lang.NoClassDefFoundError: org/hamcrest/
junit 单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
1.环境信息
jdk :jdk1.8
junit版本:4.12
jar包引用情况:没有使用maven、gradle等,只单独引用了junit-4.12.jar文件
报错信息:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
2.解决方法
官网说明:
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.11以上版本不再包含hamcrest jar包了,需要单独添加。
解决方法
- 1.junit版本降到4.10
- 2.导入hamcrest-core-1.3.jar
jar包可以去maven中央仓库下载,不过目前都是使用maven等构建工具来管理了,很古老的项目还是单独引用jar文件。
https://search.maven.org/search?q=g:org.hamcrest
更多推荐
所有评论(0)