解决Junit单元测试高版本NoClassDefFoundError异常问题
上午在正常使用Junit做测试的时候,抛出了
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Junit版本是之前maven项目下载的Junit4.3
官网查资料发现
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
从4.11开始,Junit不自带hamcrest包了,所以缺少hamcrest
猜测maven项目没问题的原因应该是:
从中央仓库拿Junit的时候应该会顺带下载hamcrest并依赖
解决方法
方法一:使用4.11以下版本,如:Junit 4.1.0
方法二:再添加一个hamcrest包,如:hamcrest-core-1.3.jar

浙公网安备 33010602011771号