Java テストの JUnit5 エンジンは JUnit3/JUnit4 も実行できる2025年03月07日 12時44分52秒

JUnit5 は JUnit4 からかなり変更されていて、移行にはコードの変更が必要になる。しかし、JUnit5 エンジンは、JUnit4 のテストも実行できるようになっているので、JUnit4 から JUnit5 に一気に書き換えなく良いのは大きな救い。

Testing in Java & JVM projects にて Gradle の設定の仕方が紹介されている。

tasks.named('test', Test) {
    useJUnitPlatform()
}


dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
    testCompileOnly 'junit:junit:4.13'
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}