NoClassDefFoundError in test: com.intellij.junit5.JUnit5TestExecutionListener

Answered

Hello!

I'm having a really strange issue while running a Spring Boot test.

When I run the test via maven -> lifecycle -> test, everything goes right; but if I run the test directly in the class it goes into an exception (see below) .

The thing is that when I run it in another PC (with the same IntelliJ version) it goes right...

I have debugged and it has troubles to load com.intellij.junit5.JUnit5TestExecutionListener from "file:/C:/Users/--userName--/AppData/Local/JetBrains/IntelliJ%20IDEA%202019.2/plugins/junit/lib/junit5-rt.jar"

The jar is there and I have even copied the one working in the other pc, but nothing works...

Thanks!

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:31)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 13 more

0
7 comments

What IDE version do you use?

Make sure you have necessary JUnit dependencies configured, please check Additional Maven Dependencies section here.

1

Hello, Andrey!

Here is the info:

The working IDE is 2020.1.1. The not working was also that version, but I updated it in order to check if it was the problem:

IntelliJ IDEA 2020.1.2 (Ultimate Edition)
Build #IU-201.7846.76, built on June 1, 2020
Runtime version: 11.0.7+10-b765.53 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0

I have understood that Spring Boot starter test provides the required dependencies and I have the same POM in both IDEs:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

 

Thank you!

0

Check that the mentioned dependencies are listed in the module's dependencies tab (Project Structure | Project Settings | Modules | Dependencies). Do you see them there?

0

Hi!

It looks that there is only one of them:

I have added all of them to the POM

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.6.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
</dependency>

 

But I get this message:

The POM for org.junit.platform:junit-platform-launcher:jar:1.6.2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

 

I have trying different options, like removing one by one and different combinations but I get the same first error. (Sometimes, before it appears, this window pops up: )

I also tried the last versions of them, but I get a different error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils

I have copied the failing test to another project in the same pc and it works. It's driven me crazy. I've tried everything: deleting .idea, caché... cloning again the repository, coping the folder plugin/junit from another place...

Is it there a way to reset the plugins or something like that?

This is the exactly point where it crashes: (from java.Lang.ClassLoader)

The jar is there and the test in the other projects loads it...

Thank you!

 

 

0

>But I get this message:

>The POM for org.junit.platform:junit-platform-launcher:jar:1.6.2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

>I have copied the failing test to another project in the same pc and it works. It's driven me crazy. 

Could be corrupted Maven libraries (then it could help to remove them from your local Maven repository - the ~/.m2 directory) or probably the spring-boot-starter parent project provides JUnit4 version, hence it must be excluded, check these threads:

https://stackoverflow.com/a/40888431/2000323

https://stackoverflow.com/a/39209047/2000323

https://dev.to/martinbelev/how-to-enable-junit-5-in-new-spring-boot-project-29a8

1

Hi, Andrey!

It's SOLVED! 

The local Maven repository should be corrupted, as you said. I deleted it, clean-install and everything went right.

Thank you very much!

1

Great, thank you for the information.

0

Please sign in to leave a comment.