3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JUnit 5がjava.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.executeでエラーになる

Posted at

現象

EclipseでJUit 5を実行しようとしたところ、下記のような例外が発生して実行できなかった。No tests found with test runner 'JUnit 5'. というポップアップが出てテストが実行できなかった。

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はこんな感じ。

		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'

原因と解決策

junit-jupiter-xxxjunit-platform-launcherのバージョンが合ってない、らしい。参照 https://stackoverflow.com/questions/57040675/java-lang-noclassdeffounderror-org-junit-platform-commons-preconditionviolation よって、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')
}

ただし、先のURLによると、場合によってはjunit-platform-commonsが無いから出る、とかも書いてある。必ずしもバージョン不整合だけが原因とは限らないかもしれない。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?