首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从intellij idea运行junit-5测试用例

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

Stack Overflow用户
提问于 2018-02-15 18:08:41
回答 3查看 7.6K关注 0票数 5

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

代码语言:javascript
复制
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)

我的样本测试课程是:

代码语言:javascript
复制
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);
    }
}

任何帮助都将不胜感激。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-02-15 18:19:12

JUnit5和IntelliJ之间存在一些可比较性问题。

根据JUnit文档 ..。

建议使用IDEA 2017.3或更高版本,因为这些较新版本的IDEA将根据项目中使用的API版本自动下载以下JAR: junit-platform-launcher、junit-木星-engine和junit-老式引擎。

来自博客帖子团队的这个IntelliJ也是相关的。在该帖子中有一个来自与您遇到相同错误的用户的评论,该用户的响应是:

我把idea更新到2017.2.6,它运行得很好。

所以,更新到IntelliJ 2017.3或更高版本,这个问题就会消失。

票数 6
EN

Stack Overflow用户

发布于 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当时还没有发布。很抱歉给您带来不便。

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

票数 3
EN

Stack Overflow用户

发布于 2018-09-04 02:47:14

我也有同样的问题。我的想法是2017.1 ver.,当我运行Junit5测试用例时,会出现blow错误。

线程"main“java.lang.NoSuchMethodError: java.lang.NoSuchMethodError中的异常

我把想法更新到2017.3.5 ver.,这个问题解决了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48813715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档