JUnit 5 fails with java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute

phenomenon

When I tried to run JUit 5 in Eclipse, I couldn't run it with the following exception. No tests found with test runner'JUnit 5'. Popped up and the tests couldn't be run.

java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/TestPlan;[Lorg/junit/platform/launcher/TestExecutionListener;)V
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

Dependencies look like this.

		testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.2'
		testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.2'
		testCompile 'org.junit.jupiter:junit-jupiter-engine:5.3.2'
		testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.3.2'

Cause and solution

It seems that the versions of junit-jupiter-xxx </ code> and junit-platform-launcher </ code> do not match. See https://stackoverflow.com/questions/57040675/java-lang-noclassdeffounderror-org-junit-platform-commons-preconditionviolation Therefore, change to use BOM.

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')
}

However, according to the above URL, it is also written that in some cases it comes out because there is no `` `junit-platform-commons```. Version inconsistency may not always be the only cause.

Recommended Posts