no tests found with test runner ‘JUnit 5‘.

no tests found with test runner ‘JUnit 5’.

springboot2.2.0,我在运行一个单元测试的时候出现了弹框错误,如图no tests found with test runner ‘JUnit 5‘.

网上看了一下大家都是说什么返回值必须要是void或者方法必须是public,如果大家是这种情况就不必再往下看了。

我来说一下我的原因是因为springboot2.1.4以上的版本与JUnit 5不兼容导致的

  • 解决方式一:升级springboot版本

这个就不必说明了,maven项目的话点开pom.xml改一下版本号重新maven update就行了,不过目前项目已经稳定的情况下更改springboot版本可能比较危险⚠️可能又会引起其他版本相关的冲突

  • 解决方式二:降低JUnit到3或者4

方式二如下图:Run -> Run Configurations -> 左侧找到你的test类->Test Runner->修改到JUnit 4,然后再重新run就可以了
no tests found with test runner ‘JUnit 5‘.
no tests found with test runner ‘JUnit 5‘.