你们好,我是金金金。

场景
- 很简单的一个测试方法

- 我的
boot
版本 :2.7.18
依赖

报错信息

排查
- 看报错信息提示无效的测试类,没有可运行的方法
看了下依赖信息,引入
spring-boot-starter-test
依赖也自动的引入了juni5
依赖,所以不需要导入junit4
依赖了,而且不用加@RunWith
就行, 而且SpringBoot2.2
开始就没有@RunWith
注解了,上面能用是因为我手动导入了junit4
的依赖,2.2之后的版本测试类上只需要一个@SpringBootTest
一个注解就可以了

造成error的原因
- 写了
@RunWith
导致,同时也不需要引入junit了,引入了spring-boot-starter-test
依赖也自动的引入了juni5
依赖
解决
把
@RunWith
去掉,把pom.xml当中的junit
依赖删除

我们来测试一下

总结
主要是因为手动写了
@RunWith
所导致。SpringBoot2.2
版本后已经没有@RunWith
了,也不需要写了,写一个@SpringBootTest
就行
- 编写有误还请大佬指正,万分感谢。