When trying to run tests using command mvn test I receive an error:
[ERROR] There was an error in the forked process
[ERROR] java.lang.NoClassDefFou
In my case the problem disappeared after deleting my local maven repository. Don't know what library caused this strange behaviour, but now everything is working fine!
java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException when trying run junit5 test with maven
This error can be come due to the version mismatch of junit-plateform-engine junit-jupiter-params and junit-platform-runner and also other respective dependencies.
So for the resolution of this issue you do not need to define version like 1.5.3 ...etc
you can define version as follows :
<dependencies>
<!--need to add for parameterized test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
**<version>${junit.jupiter.version}</version>**
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
**<version>${junit.jupiter.version}</version>**
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
**<version>${junit.platform.version}</version>**
<scope>test</scope>
</dependency>
</dependencies>
So through this compatible version jar will be added in your project and project will run successfully
adding following dependency helped in my case
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version>
</dependency>
I got the same problem with Gradle build
and I got my issue resolved using the JUnit Bill of Materials(BOM)
, which will take care of Junit's direct and transitive dependencies version.
dependencyManagement {
imports {
mavenBom "org.junit:junit-bom:5.5.2"
}
}
dependencies {
...
testCompile('org.junit.jupiter:junit-jupiter-api')
testRuntime('org.junit.jupiter:junit-jupiter-engine')
testCompile('org.junit.jupiter:junit-jupiter-params')
testCompile('org.junit.platform:junit-platform-launcher')
testCompile('org.junit.platform:junit-platform-runner')
}
NOTE: I have not specified the version because the Junit BOM will take care of the Junit dependencies' version management role.
As others suggested, using JUnit 5.5.2
version is the way to go here.
There are different alternatives to achieve this:
spring-boot-starter-parent
, you can upgrade it to 2.2.0.RELEASE
spring-boot-starter-parent
(or spring-boot-dependencies
), you can define a property to update just JUnit: <junit-jupiter.version>5.5.2</junit-jupiter.version>
Remove junit-platform-launcher
, junit-jupiter-engine
and junit-jupiter-api
.
Add junit-jupiter
. (junit-jupiter
is aggregator)
Sources: