【发布时间】:2018-02-15 18:08:41
【问题描述】:
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)
我的示例测试类是:
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);
}
}
任何帮助将不胜感激。
【问题讨论】:
-
在这里的博客blog.jetbrains.com/idea/2016/08/using-junit-5-in-intellij-idea 建议使用我添加的依赖项,现在错误消息有点不同,它说它能够找到引擎但不能找到测试方法。
-
令我惊讶的是,我的想法版本是 2016.3。将升级它并重试。
标签: java unit-testing intellij-idea junit junit5