JUnit-4.13使用報java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing錯誤


今天重新復習spring的時候,調用Junit架包來進行測試,進入其官網  https://junit.org/junit5/,點擊右上角的Junit4進行查看

2.出現了的頁面是這個樣子

 

我把這個頁面上的二個jar的下載下來了,並且還加載到了IDEA里面,沒想到還是報錯誤,

java.lang.NoClassDefFoundError

當時筆者也是相當的犯難,畢竟很久沒接觸java的里面的一些東西,不是很有印象了,而且還是在一個新的編譯器上面編譯很多的操作都是是懂非懂。后來在看文檔中終於找到了解決的方法。

去官網又看了一下,結果發現這樣一段話:

 

 

  • 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) 換用更小版本的jar包,如4.8.jar

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

   

筆者用的第二種方案


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM