我正在尝试运行以下示例单元测试用例
class ExampleUnitTest {
@Test
fun addition_is_Correct() {
assertEquals(4, (2 + 2).toLong())
}
}
但我得到以下异常
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
即使我已经更新了所有的 Junit 依赖 build.gradle 文件,如下所示
testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.spek:spek-api:1.1.5'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:4.12.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.0.0'
有什么解决办法吗?