Repository navigation
Closed
Milestone
Description
Steps to recreate:
-
In Eclipse, select a unit test to run by right-clicking and selecting: "Run Configurations." Select a JUnit execution and ensure that the JUnit5 runner is selected:

-
Click the Run button.
-
The following error is shown:

and the following stack trace is displayed:
java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.PreconditionViolationException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 7 more
Workaround: Run the mvn test on the command line and the tests will execute.
According to the following Stackoverflow: https://stackoverflow.com/questions/57040675/java-lang-noclassdeffounderror-org-junit-platform-commons-preconditionviolation adding the following dependency to the project will fix. (I've tried with the example project and it seems to work).
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version>
</dependency>
Reacted by Ran Ari-Gur
Activity
lbroman commentedon Oct 16, 2019
I got this at work today as well, and we solved it with the above suggested solution. I can prepare a PR for it if noone else already did it?
iluwatar commentedon Oct 16, 2019
Sure @lbroman, PR is welcome
kaiwinter commentedon Oct 17, 2019
Instead of inserting
junit-platform-commonsin each of the ~120 module poms a better fix would be to just update JUnit 5 to the most current version...lbroman commentedon Oct 17, 2019
Does this fix the problem?
I suggested in my PR (not visible here) that a better aproach might also be to upgrade the last junit 4 projects to jupiter and then pull the jupiter dependencies up to the root pom.
kaiwinter commentedon Oct 17, 2019
Yes it does, because JUnit 5.5.2 transitively pulls junit-platform-commons 1.5.2:
lbroman commentedon Oct 17, 2019
Tried updating to 5.5.2 and it broke the maven build, current version dates back to 2017...
junit-platform-commons is in the current dependency tree also, but 1.0.2.
Also noticed I cannot reproduce this issue on Eclipse EE but only on Eclipse Java, so is problably eclipse edition related. Will test this by managing the junit-platforms-commons version instead and see what that might bring.
kaiwinter commentedon Oct 17, 2019
Updating to 5.5.2 works for me. In addition
junit-jupiter-apihave to be added in the parent pom becausespring-boot-dependenciesimports and old version of this.Now the tests run on the command line as well as from eclipse. I'll submit a pull request.
A future improvement may be to remove all
junit-jupiter-*dependencies and replace them by the aggregator dependencyjunit-jupiterwhich was introduces with 5.4.0.oconnelc commentedon Oct 17, 2019
Another option is to switch to TestNG.
shahnawazm786 commentedon Jan 13, 2021
java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineDiscoveryListener
at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.getLauncherDiscoveryListener(LauncherDiscoveryRequestBuilder.java:241)
at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.build(LauncherDiscoveryRequestBuilder.java:235)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineDiscoveryListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.EngineDiscoveryListener
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 21 more
Fixes iluwatar#1007 by updating JUnit to 5.5.2 (iluwatar#1015)