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

2

9

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:

enter image description here

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:

enter image description here

What am I missing?

Libertinage answered 27/2, 2020 at 10:51 Comment(7)
What is the Java version?Etiolate
Does this answer your question? how to fix "The import org.junit.jupiter"?Etiolate
I honestly don't understand the link you've posted - i've found that one too, i thought eclipse installs all the needed stuff for junit to work? (since it did before) Java is Version 8 u 221, eclipse version: 2019-09 JDK 15Libertinage
The JUnit library in build path must be JUnit5. From a partial look of your package explorer I think you have added JUnit 4 or 3.Etiolate
You have a module-info.java file. Make sure you have the corresponding requires statement or consider deleting the module-info.java file. By the way, you are using an outdated Eclipse version.Bili
oh wow, thank you so much.Libertinage
Please don’t post images of code, error messages, or other textual data.Argillite
B
19

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)
Bili answered 28/2, 2020 at 8:3 Comment(0)
S
0

I had this issue too on my Eclipse IDE on one computer, but it was not happening on another computer with fresh IDE installation. That was suspicious. I tried to export/import all settings, reimport all projects, even removing their IDE configuration files, nothing helped.

Then I compared plugins installed in Eclipse IDE on both computers and I have found some differences, so I uninstalled everything mentioning M2E, and then installed just basic M2E again (after restart).

The problem has gone.

Note that there is no "test module info" support in JPMS, so every tool has it's own solution.

Shebashebang answered 21/8, 2023 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.