STS 4.6.0 Eclipse - Springboot 2.2.5 - JUnit5 failing (NoClassDefFoundError)
See original GitHub issueHello,
Launching tests with JUnit5 fails for springboot applications (2.2.5).
Reason: Eclipse 4.15 ships with JUnit5 5.6.0 Springboot 2.2.5 uses JUnit5 5.5.2 (https://github.com/spring-projects/spring-boot/blob/2.2.x/spring-boot-project/spring-boot-dependencies/pom.xml)
Result:
java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineDiscoveryListener
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
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.ClassNotFoundException: org.junit.platform.engine.EngineDiscoveryListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 18 more
Solution/Workaround:
adding/updating Junit5 version to 5.6.0 in build.gradle:
ext['junit-jupiter.version'] = '5.6.0'
I think that a warning on the download page would be nice until springboot updates their dependencies to JUnit5 5.6.0.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Eclipse No tests found using JUnit 5 caused by ...
I fixed the issue by right clicking the test and selecting 'Run Configurations' and changing the "Test runner:" selection to 'JUnit 4' as...
Read more >The java.lang.NoClassDefFoundError in JUnit - Baeldung
In this article, we'll understand why the java.lang.NoClassDefFoundError occurs in JUnit and how to fix it. This issue is mainly related to ...
Read more >Updates and Fixes in 3.8.3 - Spring
Sometimes Maven projects show up with a red error (talking about a duplicate lifecycle mapping conflict) after upgrading STS from 3.6. x to...
Read more >569860 – NoClassDefFoundError when running JUnit 5 tests ...
To demonstrate the problem, import the attached project, run "Refresh Gradle Project", and run DemoTest with "Run as ... > JUnit Test".
Read more >NoClassDefFoundError 1 « Exception « Spring Q&A
6. NoClassDefFoundError (initialization failure) - Websphere and IBM MQ stackoverflow.com. Im having a problem on a Spring based webapp that is being deployed ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another solution is, adding
testImplementation 'org.junit.platform:junit-platform-launcher'
instead ofext['junit-jupiter.version'] = '5.6.0'
to build.gradle.@martinlippert Thank you for moving this issue to the right project.
我使用使用相同的Eclipse,在一台电脑上可以执行 Junit5 ,另一台电脑上就报错,很奇怪。 Eclipse IDE for Enterprise Java Developers. Version: 2020-03 (4.15.0) Build id: 20200313-1211
junit-jupiter 插件版本是 5.6.0