question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

STS 4.6.0 Eclipse - Springboot 2.2.5 - JUnit5 failing (NoClassDefFoundError)

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
lneumeiercommented, Mar 27, 2020

Another solution is, adding testImplementation 'org.junit.platform:junit-platform-launcher' instead of ext['junit-jupiter.version'] = '5.6.0' to build.gradle.

@martinlippert Thank you for moving this issue to the right project.

2reactions
dsjtlmycommented, Sep 26, 2020

我使用使用相同的Eclipse,在一台电脑上可以执行 Junit5 ,另一台电脑上就报错,很奇怪。 Eclipse IDE for Enterprise Java Developers. Version: 2020-03 (4.15.0) Build id: 20200313-1211

junit-jupiter 插件版本是 5.6.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found