Eclipse Java IDE JUnit5: junit.jupiter.api.Assertions is not accessible

我与影子孤独终老i 提交于 2020-07-02 02:47:12

问题


I'm new to the whole programming stuff but here's my problem:

I used to add my JUnit test cases in Eclipse by right clicking on the project, and just add New > JUnit Test Case.

Currently, I am not able to implement any test methods because Eclipse tells me on the line

import static org.junit.jupiter.api.Assertions.*;

the error message

The type org.junit.jupiter.api.Assertions is not accessible.

Error I get in the IDE:

I tried the following:

  1. Reinstalling Eclipse, using a fresh workplace.
  2. Adding the JUnit to Build path

Nothing helped.

It worked and works in older projects just fine.

Here is how the Package Explorer looks:

What am I missing?


回答1:


You use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9.

Do one of the following:

  • Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
  • In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)


来源:https://stackoverflow.com/questions/60431564/eclipse-java-ide-junit5-junit-jupiter-api-assertions-is-not-accessible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!