JUnit使用时报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
特别是使用junit4.11版本,有时使用其它版本也出现这个错误。
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
这样的错误,上网查了一下,一般的解决方案是,换一个低一点的版本就好了。
还有人说,是缺少hamcrest的包。去官网又看了一下,结果发现这样一段话:
: 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.
Only includes the JUnit classes but not Hamcrest. Lets you use a different Hamcrest version.
注意黑色加下划线的部分。说明4.1.1中没有hamcrest包了,不知道作者是怎么想的。
最好的解决方法是:
(1)换成junit-4.8.jar
(2)junit-4.11.jar + hamcrest-core-1.3.jar
Junit中4.11版本和4.7版本的jar包下载资源如下:http://download.csdn.net/detail/itjavawfc/8023643