JUnit版本導致eclipse的build path加入的Maven Dependencies沒起作用


使用eclipse創建了Maven webapp project。在寫單元測試用例時,報錯@Test注解找不到,提示將JUnit添加到build path中(Add  JUnit 4 library to the build path)

點擊自動糾錯后,可以看到eclipse將自帶的JUnit4 jar包加入到了build path中。

但是其實在build path中的Maven Dependencies中是有依賴的JUnit的

為什么Maven Dependencies中已經有JUnit了,還是找不到@Test呢。

 

試了一段時間,懷疑是JUnit的版本導致,我們看到的Maven Dependencies確實含有JUnit,只不過版本是3.8.1,於是修改pom.xml,將JUnit的版本改為了4.12

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

這時候再看,就正常了。


免責聲明!

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



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