前言:
在Springboot环境下进行单元测试时,控制台爆出错误问题如下:
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.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 1
Empty test suite.
1. 查找原因
从错误代码中可以看到:
com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs
网上找了很多类似的错误,多是说Junit4 和Junit5 之间依赖冲突了,按照网友的一些解决思路进行修改,如删除Junit5 的相关依赖,发现并没有解决问题,后再Junit5 官网上发现,官网明确指出在IntelliJ IDEA 中使用Junit5 时,最好是2017.3版本之后,而我使用的正是2016.3.4的版本。
2. 解决方案:
下载IDEA 2017.3.5以上版本,所以干脆下载了2019.2的最新版本,换了版本果然没问题了。
总结:开发工具要及时升级,都2020年了,还用06年版本的,太懒了!
2019.2版本界面如下:比较炫
https://www.newasp.net/soft/506029.html
idea2019.2版本 免破解版 只需要执行一下注册脚本及修改一个配置文件即可,界面花哨