我是靠谱客的博主 想人陪板栗,最近开发中收集的这篇文章主要介绍解决SpringBoot运行Test时报错:SpringBoot Unable to find,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
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的环境即可。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是想人陪板栗为你收集整理的解决SpringBoot运行Test时报错:SpringBoot Unable to find的全部内容,希望文章能够帮你解决解决SpringBoot运行Test时报错:SpringBoot Unable to find所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复