繁体   English   中英

在IntelliJ中但不在命令行上运行JUnit 5测试时出错

[英]Error when running JUnit 5 tests in IntelliJ but not on the command line

当我尝试在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用户指南》建议使用2017.3或更高版本。

IntelliJ IDEA在IDEA 2017.3之前的版本捆绑了JUnit 5的特定版本。因此,如果您要使用JUnit Jupiter的较新版本,则由于版本冲突,IDE中的测试执行可能会失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM