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

Vin*_*ati 5 java junit unit-testing intellij-idea junit5

Junit-5测试用例成功地从命令行运行.我正在使用Maven,当我运行使用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)
Run Code Online (Sandbox Code Playgroud)

我的示例测试类是:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

gly*_*ing 6

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或更新版本,此问题应该消失.