java - 在 IntelliJ 中而不是在命令行上运行 JUnit 5 测试时出错

标签 java intellij-idea junit5

当我尝试在 IntelliJ 中运行一个简单的 JUnit 5 测试时报告了以下错误:

Feb 08, 2019 3:37:39 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable 
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests 
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List; 
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.filterAndConvertToTestClassRequests(JUnit4DiscoveryRequestResolver.java:79)
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.resolve(JUnit4DiscoveryRequestResolver.java:48)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:64) 
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:177) 
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:164) 
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:120) 
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:49) 
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)

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)

Process finished with exit code 1

这是我的pom:

<properties> 
    <java.version>1.8</java.version> 
    <junit.jupiter.version>5.3.2</junit.jupiter.version> 
</properties>

</dependencies> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-api</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-params</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency>

    <!-- Only needed to run tests in a version of IntelliJ IDEA that bundles older versions --> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-engine</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency> 
    <dependency> 
        <groupId>org.junit.platform</groupId> 
        <artifactId>junit-platform-launcher</artifactId> 
        <version>1.4.0</version> 
        <scope>test</scope> 
    </dependency> 
</dependencies>

<build> 
    <plugins> 
        <!-- JUnit 5 requires Surefire version 2.22.1 or higher --> 
        <plugin> 
            <artifactId>maven-surefire-plugin</artifactId> 
            <version>2.22.1</version> 
        </plugin> 
    </plugins> 
</build>

我正在使用 Intellij v2017.1.2。

当我从命令行运行测试时,没有报告任何错误。

我看到各种帖子报告了不同版本的 IntelliJ 的类似问题,但建议的解决方案没有帮助。

最佳答案

JUnit User Guide建议使用 2017.3 或更新版本。

IntelliJ IDEA releases prior to IDEA 2017.3 bundle specific versions of JUnit 5. Thus, if you want to use a newer version of JUnit Jupiter, execution of tests within the IDE might fail due to version conflicts.

关于java - 在 IntelliJ 中而不是在命令行上运行 JUnit 5 测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54596191/

相关文章:

java - 无法解析 IntelliJ 中的反向路由方法

java - Selenide + Junit 5 断言模式 = SOFT 不起作用

java - 在 gradle 项目中使用 Junit 和 Mockito 动态测试文件(xml、json、csv、txt)中的测试数据

java - Android 复选框选中一个变量

java - 死代码警告

Java:变量持有者及其值(value)?

java -//noinspection ForLoopReplaceableByForEach 是什么意思?

node.js - 在 Windows 10 上使用 Intellij IDEA 在 WSL 2 中运行和调试 Nodejs

java - java中如何从long double中获取int?

java - 有没有办法在 Quarkus 单元测试中回滚事务?