【问题标题】:JUnit Tests not running - Returning "Empty test suite"JUnit 测试未运行 - 返回“空测试套件”
【发布时间】:2018-04-23 20:58:04
【问题描述】:

我只是想用 Spring 在 JUnit 中运行一个简单的 get 测试:

@RunWith(SpringJUnit4ClassRunner.class)

public class ProfileTest {

    @Autowired
    ProfileDAO dao;

    @Test
    public void getProfileTest() {
        dao.getProfile("John Doe")
    }
}

但是,每次我运行它时,都会出现以下错误:

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:31)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42)
    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:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Process finished with exit code 1
Empty test suite.

我尝试过使用 File --> Invalidate Caches/Restart,但没有任何影响。根据进一步的研究,我认为这是由于 junit-jupiter-api 和 junit-command-commons 之间的版本冲突。谁能给我进一步的指导?

【问题讨论】:

标签: java spring maven intellij-idea junit


【解决方案1】:

我设法弄明白了。我从 pom 文件中删除了 junit、junit-jupiter-api 和 junit-command-commons 的依赖关系,然后只使用了 junit,如下所示:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>

【讨论】:

    猜你喜欢
    • 2012-12-04
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    相关资源
    最近更新 更多