SpringBoot整合Junit测试时要注意@SpringBootTest注解需指明启动类


具体步骤参考该文:https://blog.csdn.net/dongzi_yu/article/details/106844732

但是照做之后失败,后来发现是因为注解@SpringBootTest后面没有指明SpringBoot启动类是哪个

完整的写法应该是:

  @RunWith(SpringRunner.class)   //作用:作为启动器,让junit跟spring环境整合

  @SpringBootTest(classes={APP.class})   // 作用:1.标记当前类为测试类   2.加载spring-boot启动类,启动spring-boot

 

在未指定启动类的情况下会报:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

 

参考:

        https://blog.csdn.net/qq_42011565/article/details/99331353


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM