springBoot JunitTest的使用以及如何在junit启动前加载
生活随笔
收集整理的這篇文章主要介紹了
springBoot JunitTest的使用以及如何在junit启动前加载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
springBoot JunitTest的使用
@SpringBootTest(classes = {Application.class},webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestExecutionListeners(listeners = {TestListener.class, DependencyInjectionTestExecutionListener.class }) @TestPropertySource(locations = {"file:../config/prop.properties"}) public class Test {@Autowiredprivate Service Service;@Testpublic void test(){Service.testMethod("11111111");}}首先是@TestExecutionListeners 注解,這個注解可以在junit測試開始之前進行設置環境變量或做其他的事情
@TestPropertySource 這個注解可以為environment加載一些配置文件,這些配置文件必須是properties,使用過程中發現yaml解析不了。
總結
以上是生活随笔為你收集整理的springBoot JunitTest的使用以及如何在junit启动前加载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一次C端线上缓存问题的总结
- 下一篇: mac的ideal终端中mvn命令不生效