netflix测试能不能看_Netflix监管者测试–引入知事,准官员
netflix測(cè)試能不能看
考慮一個(gè)典型的Netflix Governator junit測(cè)試。
該測(cè)試?yán)昧薔etflix Governator提供的Junit規(guī)則支持,并測(cè)試了Governator的某些功能集-引導(dǎo)模塊,程序包掃描,配置支持等。
但是,該測(cè)試有很多樣板代碼,我認(rèn)為可以通過使用Junit Runner類型的模型來減少。 作為這個(gè)概念的證明,我將介紹一個(gè)沒有想象力的項(xiàng)目– Governorator-junit-runner ,現(xiàn)在考慮使用該庫重寫的同一測(cè)試:
@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());}}現(xiàn)在,大多數(shù)樣板都在Junit運(yùn)行器中實(shí)現(xiàn),并且通過LifecycleInjectorParams批注傳遞引導(dǎo)監(jiān)管程序所需的參數(shù)。 測(cè)試實(shí)例本身是一個(gè)綁定的組件,因此可以被注入,這樣,需要測(cè)試的實(shí)例可以被注入測(cè)試本身并被斷言。 如果您想要更細(xì)粒度的控制,則可以將LifecycleManager本身注入到測(cè)試中!:
@Inject private Injector injector;@Inject private LifecycleManager lifecycleManager;如果您對(duì)此感興趣,可以在此處的項(xiàng)目現(xiàn)場(chǎng)找到更多示例。
翻譯自: https://www.javacodegeeks.com/2015/02/netflix-governator-tests-introducing-governator-junit-runner.html
netflix測(cè)試能不能看
總結(jié)
以上是生活随笔為你收集整理的netflix测试能不能看_Netflix监管者测试–引入知事,准官员的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux新建文件的命令有哪些(linu
- 下一篇: jdk8读取文件_JDK 7和JDK 8