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);
}
}任何帮助都将不胜感激。
发布于 2018-02-15 18:19:12
发布于 2018-02-15 18:20:00
从官方评论来看,您可能需要升级IDE版本
IDE对旧的junit 5启动程序jar具有编译依赖性,并且它与当前发布的版本不兼容。因此,您可以选择更新IDE,以便它与您使用的junit版本兼容,或者降低junit版本的级别(检查IDEA_INSTALLATION_HOME/plugins/junit/lib中捆绑的版本)。2017.1只在实验上支持junit 5,因为junit 5当时还没有发布。很抱歉给您带来不便。
发布于 2018-09-04 02:47:14
我也有同样的问题。我的想法是2017.1 ver.,当我运行Junit5测试用例时,会出现blow错误。
线程"main“java.lang.NoSuchMethodError: java.lang.NoSuchMethodError中的异常
我把想法更新到2017.3.5 ver.,这个问题解决了
https://stackoverflow.com/questions/48813715
复制相似问题