日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Netflix监管者测试–引入了知事-Junit-runner

發布時間:2023/12/3 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Netflix监管者测试–引入了知事-Junit-runner 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

考慮一個典型的Netflix Governator junit測試。

public class SampleWithGovernatorJunitSupportTest {@Rulepublic LifecycleTester tester = new LifecycleTester();@Testpublic void testExampleBeanInjection() throws Exception {tester.start();Injector injector = tester.builder().withBootstrapModule(new SampleBootstrapModule()).withModuleClass(SampleModule.class).usingBasePackages("sample.gov").build().createInjector();BlogService blogService = injector.getInstance(BlogService.class);assertThat(blogService.get(1l), is(notNullValue()));assertThat(blogService.getBlogServiceName(), equalTo("Test Blog Service"));}}

該測試利用了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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。