Skip to content

NoClassDefFoundError for PreconditionViolationException when running JUnit5 tests #1020

@michalhosala

Description

@michalhosala

I can no longer run unit tests for my spring app within VSCode IDE, am only getting the following error when trying to do so:

java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:90)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:48)
	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.commons.PreconditionViolationException
	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:522)

PreconditionViolationException is now deprecated, see here, so it would seem Java Test Runner is not aware of it or what. Currently my build.gradle has junit dependencies like this:

        testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.0"
        testImplementation "org.junit.jupiter:junit-jupiter-params:5.6.0"
        testImplementation "org.springframework.boot:spring-boot-starter-test:2.2.8.RELEASE"
        testRuntime "org.junit.jupiter:junit-jupiter-engine:5.6.0"

I had a look at what seemed like a related issue but none of the workarounds from there worked for me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions