Netflix监管者测试–引入了知事-Junit-runner
生活随笔
收集整理的這篇文章主要介紹了
Netflix监管者测试–引入了知事-Junit-runner
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
考慮一個典型的Netflix Governator junit測試。
該測試利用了Netflix Governator提供的Junit規則支持,并測試了Governator的某些功能集-引導模塊,程序包掃描,配置支持等。
但是,該測試有很多樣板代碼,我覺得可以通過使用Junit Runner類型的模型來減少。 作為這個概念的證明,我將介紹一個沒有想象力的項目– Governorator-junit-runner ,現在考慮使用該庫重寫的同一測試:
@RunWith(GovernatorJunit4Runner.class) @LifecycleInjectorParams(modules = SampleModule.class, bootstrapModule = SampleBootstrapModule.class, scannedPackages = "sample.gov") public class SampleGovernatorRunnerTest {@Injectprivate BlogService blogService;@Testpublic void testExampleBeanInjection() throws Exception {assertNotNull(blogService.get(1l));assertEquals("Test Blog Service", blogService.getBlogServiceName());}}現在,大多數樣板都在Junit運行器中實現,并且通過LifecycleInjectorParams批注傳遞引導監管程序所需的參數。 測試實例本身是一個綁定的組件,因此可以被注入到其中,這樣可以將需要測試的實例注入到測試本身中并聲明。 如果您想要更細粒度的控制,則可以將LifecycleManager本身注入到測試中!:
@Inject private Injector injector;@Inject private LifecycleManager lifecycleManager;如果您對此感興趣,可以在此處的項目現場找到更多示例。
翻譯自: https://www.javacodegeeks.com/2015/02/netflix-governator-tests-introducing-governator-junit-runner.html
總結
以上是生活随笔為你收集整理的Netflix监管者测试–引入了知事-Junit-runner的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10电脑c盘清理垃圾文件(win1
- 下一篇: l360打印照片设置(l360换打印头)