天天看點

Junit4 - The type org.junit.jupiter.api.Assertions is not accessible測試方法模闆錯誤解決方法記錄

eclipse中建立Junit4單元測試出現如下問題:

Junit4 - The type org.junit.jupiter.api.Assertions is not accessible測試方法模闆錯誤解決方法記錄

出錯的建立方法:

1)先建一個Java項目

2)建立一個新的包

3)編寫一個用于被測試的類

4)導入Junit4的jar包

項目上右鍵 — Build Path — Add Libraries… — Junit — Next — junit4 — Finish

Junit4 - The type org.junit.jupiter.api.Assertions is not accessible測試方法模闆錯誤解決方法記錄

5)建立測試類

目前包右鍵 — NEW — Junit Text Case

這個測試類會自動為我們建立一個測試方法模闆

————————————————————————————

我目前出現的錯誤就是出現在這個模闆上

上面同樣的步驟建立junit5單元測試,出現了一樣的錯誤

我使用的eclipse版本是“14.0.1”,之前看到一個改變版本号解決錯誤的部落格,我試了一下沒有成功。

推測出現錯誤的步驟應該是步驟4,導入junit的jar包出錯了

我的解決方法:

Junit官網:junit官網

1)下載下傳

junit-4.13.jar

hamcrest-core-1.3.jar

2)移除上面在項目中已經導入的Junit的jar包

3)在項目中建立

libs檔案夾

,将

junit-4.13.jar

hamcrest-core-1.3.jar

複制到檔案夾中

4)右鍵單擊

junit-4.13.jar

Build Path — Add To Build Path

5)右鍵單擊

hamcrest-core-1.3.jar

Build Path — Add To Build Path

6)将上面步驟五建立的測試類删除,重複步驟五,建立測試方法模闆

Junit4 - The type org.junit.jupiter.api.Assertions is not accessible測試方法模闆錯誤解決方法記錄

歐克

Junit4 - The type org.junit.jupiter.api.Assertions is not accessible測試方法模闆錯誤解決方法記錄