目录 SpringBoot运行Test时报错 错误详情 解决办法 SpringBootTest单元测试报错 SpringBoot运行Test时报错 运行Test时的报错信息:SpringBoot Unable to find a @SpringBootConfiguration 错误详情 今天做SpringBo
目录
- SpringBoot运行Test时报错
- 错误详情
- 解决办法
- SpringBootTest单元测试报错
SpringBoot运行Test时报错
运行Test时的报错信息:SpringBoot Unable to find a @SpringBootConfiguration
错误详情
今天做SpringBoot配置邮件发送的时候,运行测试类,报如下错误:

说找不到@SpringBootConfiguration注解,其实是有的,检查了下启动类和被测试类的细节,都没问题,查询的很多CSDN答案都是互相抄来抄去。。。。比如测试类的包名和启动类的包名一致等解决办法,试了都没用。
解决办法
原来还要在测试类里制定启动类。。。解决办法很简单,把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像这样:

注:我这里的启动类名为App,更改的时候根据自己启动类名来改

SpringBootTest单元测试报错
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { DataRulesApplication.class })
@EnableAutoConfiguration
//@SpringBootTest(classes = { DataRulesApplication.class })
public class HuaboAddressTest extends AbstractTestNGSpringContextTests {
@Autowired
private HuaboAddressServiceImpl johnyService;
@Test
public void queryState() {
//johnyService.resetAllDistricts();
long startTime = System.currentTimeMillis();
// johnyService.resetAllDistricts();
// johnyService.batchUpdate2();
// johnyService.batchupdate3();
//johnyService.resetAllDistricts();
johnyService.updateBatch();
long endTime = System.currentTimeMillis();
System.out.println("执行时间:" + (endTime - startTime));
// long startTime = System.currentTimeMillis();
// johnyService.select1();
// long endTime = System.currentTimeMillis();
// System.err.println("执行时间1:"+(endTime-startTime));
// startTime = System.currentTimeMillis();
// johnyService.select2();
// endTime = System.currentTimeMillis();
// System.err.println("执行时间2:"+(endTime-startTime));
}
@Test
public void check() {
}
@Test
public void register() {
}
@Test
public void detail() {
}
@Test
public void queryCategory() {
}
}

其实只需要在setting中设置运行test的环境即可。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持自由互联。
