10

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?

7
  • What is the Java version? Commented Feb 27, 2020 at 10:53
  • Does this answer your question? how to fix "The import org.junit.jupiter"? Commented Feb 27, 2020 at 10:55
  • 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 15 Commented Feb 27, 2020 at 10:58
  • 1
    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. Commented Feb 27, 2020 at 11:01
  • 1
    oh wow, thank you so much. Commented Feb 27, 2020 at 11:06

2 Answers 2

21

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)
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.