1. 程式人生 > >spring系列---junit測試

spring系列---junit測試

1、junit對應的jar包 

junit-4.12.jar 

2、使用junit報錯,主要是版本的問題,高版本不包含有些功能

下載了最新的JUnit版本,是4.12,結果嘗試使用發現總是報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.

解決辦法是 

(1)換成junit-4.8.jar

(2)junit-4.12.jar + hamcrest-core-1.3.jar