I'm currently trying to create JUnit tests for my Java project (eclipse). However, a weird error keeps showing whenever I add a new JUnit Test Case to my project: https://ibb.co/ekon9J When I try to use the Quick Fix function of the Eclipse, it adds the JUnit 5 to the build path again, although it's already there. All seems to be set up correctly, but it's still not working. I tried cleaning/closing the project as someone suggested in a similar thread. Unfortunately, nothing helped me. Does anyone have an idea on what's going on here?
[EDIT]: Here's the print screen of the Java Build Path libraries tab: https://ibb.co/dUgiGy
The mentioned package/classes are not present in the compile time classpath. Basically, Java has no idea what you're talking about when you say to import this. It can't find them in the classpath.
Download the latest jar from, https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api/5.0.0-M1 Place it in /WEB-INF/lib folder of the webapp project and this error should disappear.
Finally, got an answer. In my case, the solution was to change the JRE in Build path to Java SE 1.8. Now everything works fine.
Because it is a modular project, JUnit 5 must be on the modulepath and the following line must be in
module-info.java
:If you do not want JUnit in the
module-info.java
, you have to separate the test code as shown in this short video.