简体   繁体   English

JUnit测试未运行-返回“空测试套件”

[英]JUnit Tests not running - Returning “Empty test suite”

I'm just trying to run a simple get test in JUnit, with Spring: 我只是想用Spring在JUnit中运行一个简单的get测试:

@RunWith(SpringJUnit4ClassRunner.class)

public class ProfileTest {

    @Autowired
    ProfileDAO dao;

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

However, everytime I run it, it errors out with the following: 但是,每次我运行它时,都会出现以下错误:

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.

I've tried using File --> Invalidate Caches/Restart, but to no affect. 我试过使用文件->使缓存无效/重新启动,但是没有任何影响。 Based on further research, I think it's due to a version conflict between junit-jupiter-api and junit-command-commons. 根据进一步的研究,我认为这是由于junit-jupiter-api和junit-command-commons之间的版本冲突造成的。 Can anyone give me further direction? 谁能给我进一步的指示?

I managed to figure it out. 我设法弄清楚了。 I deleted the dependencies from the pom file for junit, junit-jupiter-api and junit-command-commons, and then just used junit, like so: 我从pom文件中删除了junit,junit-jupiter-api和junit-command-commons的依赖项,然后仅使用junit,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM