繁体   English   中英

无法从intellij想法运行junit-5测试用例

[英]Unable to run junit-5 test cases from intellij idea

Junit-5测试用例成功地从命令行运行。 我正在使用Maven,当我使用mvn clean install运行时, mvn clean install测试用例运行成功,但是当使用IntelliJ运行单个测试用例时,它失败并出现以下错误。

Feb 15, 2018 11:33:41 PM org.junit.jupiter.engine.discovery.JavaElementsResolver resolveMethod
WARNING: Method 'public static java.util.Collection com.softiventure.dtos.junit.parametrized.NestedParametrizedTest$sumTest.parameters()' could not be resolved.
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:59)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    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.AppMain.main(AppMain.java:147)

我的示例测试类是:

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@DisplayName("Pass paramters ")
public class ParametrizedJunit5Test {

    @DisplayName("Should pass a non-null message to our test method")
    @ParameterizedTest
    @ValueSource(strings = {"Hello", "World"})
    void shouldPassNonNullMessageAsMethodParameter(String message) {
        assertNotNull(message);
    }
}

任何帮助将非常感激。

JUnit5和IntelliJ之间存在一些兼容性问题。

根据JUnit文档 ......

建议使用IDEA 2017.3或更新版本,因为这些较新版本的IDEA将根据项目中使用的API版本自动下载以下JAR:junit-platform-launcher,junit-jupiter-engine和junit-vintage-engine。

IntelliJ团队的这篇博文也很有用。 来自遇到与您相同的错误的用户对该帖子发表评论 ,该用户的回复是:

我将想法更新到2017.2.6,效果很好。

因此,更新到IntelliJ 2017.3或更新版本,此问题应该消失。

从官方评论,您可能必须升级您的IDE版本

IDE对旧的junit 5启动程序jar具有编译依赖性,并且与当前发布的版本不兼容。 因此,您可以选择更新IDE,使其与您使用的junit版本兼容,或者降级junit版本(检查IDEA_INSTALLATION_HOME / plugins / junit / lib中捆绑的版本)。 2017.1只有junit 5的实验支持,因为当时尚未发布junit 5。 抱歉给你带来不便。

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000791190-Intellij-does-not-run-Junit5-tests

我有同样的问题。 我的IDEA版本是2017.1 ver. ,当我运行Junit5测试用例时,发生了打击错误。

线程“main”中的异常java.lang.NoSuchMethodError:org.junit.platform.launcher.Launcher.execute(Lorg / junit / platform / launcher / LauncherDiscoveryRequest;)V

我将IDEA更新到2017.3.5 ver. 那个问题已经解决了

暂无
暂无

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

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