java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException when trying run junit5 test with maven

后端 未结 8 1874
抹茶落季
抹茶落季 2020-12-10 00:56

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         


        
8条回答
  •  粉色の甜心
    2020-12-10 01:24

    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.

提交回复
热议问题