记录使用SpringBoot测试类时遇到的两个问题

1.java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

异常信息

在这里插入图片描述

问题出现的原因有两个

1.需要将测试类所在的包名,改成与其他分支的包名,如下图(参考)

在这里插入图片描述

2.在测试类中的@SpringBootTest注解中的calsses属性值等于启动类.class,用来加载启动类,如图所示(参考)

在这里插入图片描述

2.java.lang.IllegalStateException: Shutdown in progress

异常信息

在这里插入图片描述

问题原因:测试结束Shutdown in progress释放资源

解决方案

在测试方法的结尾加上一个条件未true的while循环即可

如图所示(参考)

在这里插入图片描述

发布了30 篇原创文章 · 获赞 40 · 访问量 6497

猜你喜欢

转载自blog.csdn.net/ScholarTang/article/details/103452623