【发布时间】: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 之间的版本冲突。谁能给我进一步的指导?
【问题讨论】:
-
那么您使用的是 Junit 4 还是 Junit 5?你的跑步者说“4”,但你的错误说“5”。
标签: java spring maven intellij-idea junit