Spring4.3.8使用單元測試報錯
1.新增junit-4.8.2.jar,測試出現問題報錯java.lang.noclassdeffounderror:org/apache/commons/logging/LogFactory,查詢發現是缺少支援jar,新增支援commons-logging-1.1.3.jar
2.繼續報錯需要junit-4.12以上
3.新增支援junit-4.12.jar
4.執行繼續報錯,java.lang.noclassdeffounderror:org/hamcrest/SelfDescribing
終極解決,查詢發現:
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中沒有hamcrest包了
最好的解決方法是:
使用是匯入包的方案:junit.jar + hamcrest-core.jar + hamcrest-library.jar
分別下載所用jar,hamcrest-core-1.3.jar和hamcrest-library-1.3.jar
執行測試,問題解決。