下載下傳了最新的JUnit版本,是4.13,結果嘗試使用發現總是報java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing這樣的錯誤,
- 一般的解決方案是,換一個低一點的版本就好了
- 還有人說,是缺少hamcrest的包。去官網又看了一下,結果發現這樣一段話:
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.1.2中沒有hamcrest包了
解決方案
- 換成junit-4.8.jar
- junit-4.12.jar + hamcrest-core-1.3.jar