java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters Junit5 with eclipse

Viewed 10485

I'm receiving the following exception:

java.lang.NoClassDefFoundError: org/junit/platform/engine/ConfigurationParameters
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
    at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350)
    at java.base/java.lang.Class.newInstance(Class.java:645)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:371)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:366)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:310)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:225)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 13 more

Running JUnit 5 in an Eclipse project (no Maven). Does anyone know what causes this issue? Eclipse version: 2020-12 JUnit Version: 5

I was expecting JUnit 5 to run on Eclipse without further action.

5 Answers

The same error occured to me.

Solution: I had to add the JUnit library to the buildpath. Right click the class -> build path -> configure buildpath -> add libraries -> add JUnit

At this point one should add the new library not to the module path but to the entire class path.

JUnit tests are now running for me, though i had the same error as @AlBlue.

I had this issue because I configured the buildpath with JUnit 5 to the modulepath. Instead you need to configure it in the Classpath.

EDIT As mentioned in the comment: There are two locations that a library can be added to build path and module path. If you add Junit on module path, the classes are not visible, as they are not packaged in a module

It looks like you’re missing one of JUnit’s dependencies, which means that the class isn’t loading. Check you have all of the necessary dependencies in place especially if you’re not using a build tool like Maven.

Add Junite library to Classpath instead of Modulepath, in Java build path window, it solved the problem for me

My problem is resolved as I was trying to run junit test class on STS 4 MacOS. I did:

  1. Either add all required jar file of JUnit 5 Jupiter file -

    • junit-jupiter-api-5.8.0.jar
    • annotations-13.0.jar
    • apiguardian-api-1.1.2.jar
    • core-0.6.8.jar
    • hoplite-core-2.1.3.jar
    • hoplite-yaml-2.1.3.jar
    • junit-jupiter-engine-5.8.0.jar
    • junit-platform-commons-1.8.0.jar
    • junit-platform-engine-1.8.0.jar
    • junit-platform-launcher-1.8.0.jar
    • junit5-0.6.8.jar
    • kotlin-reflect-1.6.20.jar
    • kotlin-stdlib-1.6.20.jar
    • kotlin-stdlib-common-1.6.20.jar
    • kotlin-stdlib-jdk7-1.6.10.jar
    • kotlin-stdlib-jdk8-1.6.10.jar
    • opentest4j-1.2.0.jar
    • slf4j-api-1.7.32.jar
  2. OR add dependency in pom.xml file

<dependency>
   <groupId>com.github.lemfi.kest</groupId>
   <artifactId>junit5</artifactId>
   <version>0.6.8</version>
</dependency>
Related