解决java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use

1.遇到的问题:
在单元测试的时候报:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use

解决java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use

问题有可能是有两个:
1.你没有写启动类:解决java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use

2.虽然你写了启动类但是你的启动类所在的包和单元测试的包不在同一级根目录下。如上图:一个是在cn.gitv.pro.charging.sncmcc,另一个是在cn.gitv.pro.charging,他们不在同一个目录下所以报 找不到启动类:
放在同一个包目录下就解决这个问题了。

解决java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use

总结:单元测试的测试类一定要和启动类在同一个根目录下。