【问题标题】:Running JUnit tests in IntelliJ, getting: java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull在 IntelliJ 中运行 JUnit 测试,得到:java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull
【发布时间】:2018-09-13 01:30:45
【问题描述】:

我正在尝试在 IntelliJ 中运行单元测试,并且正在获取堆栈跟踪:

线程“主”java.lang.NoSuchMethodError 中的异常:org.junit.platform.commons.util.Preconditions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object; 在 org.junit.platform.launcher.core.DefaultLauncher.registerTestExecutionListeners(DefaultLauncher.java:71) 在 com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:44) 在 com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 在 com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) 在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

谷歌搜索错误消息没有帮助 - 我返回的所有命中都与 Gradle 依赖项有关,但我使用的是 Maven(并且我已经三重检查了我的依赖项)。这是我的pom:

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

令人沮丧的是,这确实适用于不同的项目,所以我不确定这里出了什么问题。

【问题讨论】:

    标签: intellij-idea junit


    【解决方案1】:

    没关系,我想通了——以防万一其他人有同样的问题:原来我的单元测试是导入 org.junit.Test,而不是 org.junit.jupiter.api.Test,但我没有'不要在我的 pom.xml 中声明对 junit-vintage 的依赖。解决方案是在我的 pom 中明确声明 junit-vintage 的正确版本(在我的情况下为 4.12.0-M3),或者将我的单元测试切换到导入 org.junit.jupiter.api.Test。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多