gpt4 book ai didi

android - java.lang.NoSuchMethodError : org. junit.platform.launcher.Launcher.execute

转载 作者:行者123 更新时间:2023-12-01 23:35:31 26 4
gpt4 key购买 nike

我正在尝试运行以下示例单元测试用例

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'

有什么解决办法吗?

最佳答案

TL;DR 根据 IDEA_INSTALLATION_HOME/plugins/junit/lib 中最初随 IDEA 一起提供的版本,降级 pom.xml 中的依赖项>

<小时/>

更长的版本:

假设您使用的 Intellij IDEA 版本早于 2017.3;那么你有这些选择作为另一个 SO 问题的官方答案: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000791190-Intellij-does-not-run-Junit5-tests

将其粘贴到此处以使其更明显:

IDE has compilation dependency on the old junit 5 launcher jar and it is not compatible with current released version. So you have a choice to update IDE so it will be compatible with the junit version you use or to downgrade the junit version (check what version was bundled in IDEA_INSTALLATION_HOME/plugins/junit/lib). 2017.1 had only experimental support for junit 5 as junit 5 was not released yet at that time. Sorry for the inconvenience.

因此,请转到您的 IDEA_INSTALLATION_HOME/plugins/junit/lib 文件夹并检查其中找到的 jar 文件名称中的版本。应该是这样的:

user@comp:IDEA_INSTALLATION_HOME/plugins/junit/lib]$ ls
idea-junit.jar junit-platform-runner-1.0.0-M4.jar
junit5-rt.jar junit-platform-suite-api-1.0.0-M4.jar
junit-jupiter-api-5.0.0-M4.jar junit-rt.jar
junit-jupiter-engine-5.0.0-M4.jar junit-vintage-engine-4.12.0-M4.jar
junit-platform-commons-1.0.0-M4.jar opentest4j-1.0.0-M2.jar
junit-platform-engine-1.0.0-M4.jar resources_en.jar
junit-platform-launcher-1.0.0-M4.jar

现在,在模块的 pom.xml properties 设置中使用 junit- 文件名的版本后缀:

<project>
...
<properties>
<junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
<junit.platform.version>1.0.0-M4</junit.platform.version>
<junit.vintage.version>4.12.0-M4</junit.vintage.version>
...
</properties>
...
</project>

我可以确认,在更改为旧版本后,我可以运行使用 org.junit.jupiter 包的测试类。在此之前,我在尝试运行测试时不断收到NoSuchMethodError

关于android - java.lang.NoSuchMethodError : org. junit.platform.launcher.Launcher.execute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50323335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com