使用Junit 5运行测试时的java.lang.NoSuchMethodError [英] java.lang.NoSuchMethodError when run test with Junit 5

查看:6279
本文介绍了使用Junit 5运行测试时的java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的测试来尝试Junit 5:

I created a simple test to try Junit 5:

import org.junit.jupiter.api.Test;
public class MyTest {

    @Test
    public void testJupiter() {
        System.out.println("test");
    }
}

这是我使用的依赖项:

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.0.0</version>
            <scope>test</scope>
        </dependency>

堆栈跟踪是下一个:

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:30)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
    at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

任何想法出了什么问题?

Any ideas what went wrong?

推荐答案

我看到你使用的是IntelliJ,它只支持特定版本的jUnit5。

I see that you are using IntelliJ which supports just specific versions of jUnit5.

Junit5 - 在IntelliJ中运行测试

尝试例如

<version>5.0.0-M4</version>

这篇关于使用Junit 5运行测试时的java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆