Spring Boot单元测试报错!
报错信息:
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
详细信息
报错原因
测试类和Spring Boot启动类不在一个目录下。
解决办法:
将启动类和测试类放在同一个包下就可以了。
何为同一个包下,即路径名相同即可。
如都在com.xixihaha下
启动类测试类
或者给测试类的注解加上@SpringBootTest(classes = {启动类类名.class})
谢谢!