软件编程
位置:首页>> 软件编程>> java编程>> 解决SpringBoot运行Test时报错:SpringBoot Unable to find

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

作者:周小枫  发布时间:2021-11-15 16:48:56 

标签:SpringBoot,Test,报错

SpringBoot运行Test时报错

运行Test时的报错信息:SpringBoot Unable to find a @SpringBootConfiguration

错误详情

今天做SpringBoot配置邮件发送的时候,运行测试类,报如下错误:

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

说找不到@SpringBootConfiguration注解,其实是有的,检查了下启动类和被测试类的细节,都没问题,查询的很多CSDN答案都是互相抄来抄去。。。。比如测试类的包名和启动类的包名一致等解决办法,试了都没用。

解决办法

原来还要在测试类里制定启动类。。。解决办法很简单,把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像这样:

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

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

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

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() {
   }
}

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

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

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

来源:https://blog.csdn.net/x1825048925/article/details/103222867

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com