问题在线
新项目,想写一个springboot测试类,但是测试方法报错
Unable to find a @SpringBootConfguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
原因
测试包和项目包不对应
解决方案
1: 新建测试包的包路径和项目启动类包路径相对应
就是如果程序的启动类在com.shaoming包下
那么我们编写的测试类应该也在com.shaoming包下
《简单来说:我们编写的测试类必须要和程序的启动类SpringBootDemoApplication这个类所在的目录结构要相同或者是在该目录的子目录也可以》
2: 我们可以在测试类的@SpringBootTest( classes= xxxxx.class )
这个注解里面加上我们该模块的启动类的字节码