Intellij idea 在IntelliJ中运行JUnit测试,获取:java.lang.NoSuchMethodError:org.JUnit.platform.commons.util.Premissions.notNull

Intellij idea 在IntelliJ中运行JUnit测试,获取:java.lang.NoSuchMethodError:org.JUnit.platform.commons.util.Premissions.notNull,intellij-idea,junit,Intellij Idea,Junit,我尝试在IntelliJ中运行单元测试,并获得堆栈跟踪: 线程“main”java.lang.NoSuchMethodError中出现异常:org.junit.platform.commons.util.premissions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object; 位于org.junit.platform.launcher.core.DefaultLauncher.registerTestExecuti

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

线程“main”java.lang.NoSuchMethodError中出现异常:org.junit.platform.commons.util.premissions.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(本机方法)处 位于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>

org.junit.jupiter
JUnitJupiter api
5.0.0-M3
测试
org.junit.jupiter
朱尼特木星发动机
5.0.0-M3
测试
org.junit.platform
junit平台发射器
1.0.0-M3
测试
朱尼特
朱尼特
4.12
测试

令人沮丧的是,这确实在另一个项目中起作用,所以我不确定这里出了什么问题。

没关系,我想出来了——以防其他人也有同样的问题:原来我的单元测试是导入org.junit.test,而不是org.junit.jupiter.api.test,但我没有声明对junit-v的依赖关系解决方案是在我的pom中显式声明junit vintage的正确版本(在我的例子中是4.12.0-M3),或者将我的单元测试切换到import org.junit.jupiter.api.Test