SpringBoot运行Test时报错问题 解决SpringBoot运行Test时报错:SpringBoot Unable to find

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

SpringBoot运行Test时报错问题 解决SpringBoot运行Test时报错:SpringBoot Unable to find

周小枫   2021-10-14 我要评论
想了解解决SpringBoot运行Test时报错:SpringBoot Unable to find的相关内容吗,周小枫在本文为您仔细讲解SpringBoot运行Test时报错问题的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:SpringBootTest,运行Test报错,SpringBoot报错,下面大家一起来学习吧。

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的环境即可。

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们