Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory

The problem

Whenever I run my projects JUnit test (using JUnit 5 with Java 9 and Eclipse Oxygen 1.a) I encounter the problem that eclipse can't find any tests.

The description

Under the run configuration, eclipse can't even find the method which is annotated with @Test, but instead only shows me "(all methods)". The following picture hopefully gives a better glimps of my setup:

https://imgur.com/a/FTe9c

Console output:

java.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:31)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.base/java.lang.Class.newInstance(Unknown Source)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:368)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:363)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:307)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:222)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.core.LauncherFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 11 more

What I tried so far

I've already tried

  • to remove the test folder from build path and add it again.
  • to start the test with hovering over the method annotated with @Test and then click "Run as JUnit Test".
  • remove JUnit from Buildpath and add it again
  • restart eclipse
  • I've also moved the project whole project from one machine to another machine and tried it with the provided eclipse installation there
  • to rename the test method.
  • to retype the @Test annotation

Some of these steps can be found here, but in the end the problem remained.

like image 247
ShadowDragon Avatar asked Sep 25 '22 08:09

ShadowDragon


People also ask

How do you fix No tests found with test runner JUnit 5?

Solution 3 The spring boot test dependency must be included in the pom. xml file. This dependency will add all the test jar files needed to the class path of the project test runtime environment. Check the JUnit jar dependency in your pom.

How do I change test runner in eclipse?

All tests should be run with jUnit3, if i run a non-configured Test, it tries to use the default-TestRunner (jUnit4). So, i have to go into the run/debug configuration, change the TestRunner to "jUnit3" and run it again. On EVERY Test.


Video Answer


1 Answers

I fixed the issue by right clicking the test and selecting 'Run Configurations' and changing the "Test runner:" selection to 'JUnit 4' as shown here:

Screenshot of run configruations

I ran the test again and it worked.

like image 172
stringVector Avatar answered Oct 17 '22 16:10

stringVector