我只是想在JUnit中运行一个简单的get测试,使用Spring:
@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 - >使高速缓存/重新启动无效,但不会产生任何影响。基于进一步的研究,我认为这是由于junit-jupiter-api和junit-command-commons之间的版本冲突。谁能给我进一步指导?
答案 0 :(得分:0)
我设法搞清楚了。我从junit,junit-jupiter-api和junit-command-commons的pom文件中删除了依赖项,然后只使用了junit,如下所示:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>