问题
我用的idea版本是2021.1 报错截图类似下图。我忘截图了。情况是一次电脑没电关机后再测试就一直报错了。
解决方法
是idea升级到2021.2就好了。方法来源于youtrack。
帖子最后说“issue with junit 4.11 must be resolved in IDEA 2021.2 EAP: junit 5 doesn’t support junit 4.11 and most probably your added junit 4.13.2 land after junit 4.11 (bundled in another jar) on the classpath. Sorry for the inconvenience”(关于junit 4.11的问题必须在IDEA 2021.2 EAP中解决:junit 5不支持junit 4.11,而且很可能你在classpath上junit 4.11(捆绑在另一个jar中)之后加入了junit 4.13.2。很抱歉给你带来的不便) 跟这个发帖人说的细节相关的比较多。但是还是注意到需要升级。
补充信息
1 junit
idea 再启动时,把项目的测试框架认为成junit5了。 JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage,但我项目本身用的是junit4. 所以本来不用junt-platform,后来需要了。from 51cto的文章
2 如何debug
org.junit.platform.commons.JUnitException and org.junit.jupiter.api.Test, 用双shift快捷键去查这两个类,看来自什么包。后来发现是来自一个其它包引入的jetty包里。是直接把 .class给打包进去了。from youtrack
3 不要升级太高版本的idea
因为太高版本的内置的maven升级,还得调maven的配置。
4 其它经验
也有很多帖子写了最后给maven里加上包引用解决了。不想冒别的风险,直接引入包也行。