android – 在使用Dagger2时创建测试依赖项

android – 在使用Dagger2时创建测试依赖项,第1张

概述在阅读匕首2的文档时,在构建应用程序进行测试时,找不到提供依赖关系的简单方法.我发现的唯一线索是: Dagger 2 doesn’t support overrides. Modules that override for simple testing fakes can create a subclass of the module to emulate that behaviour. Modu 在阅读匕首2的文档时,在构建应用程序进行测试时,找不到提供依赖关系的简单方法.我发现的唯一线索是:

Dagger 2 doesn’t support overrIDes. Modules that
overrIDe for simple testing fakes can create
a subclass of the module to emulate that behavIoUr.
Modules that use overrIDes and rely on dependency injection
should be decomposed so that the overrIDden modules are instead
represented as a choice between two modules.

@H_419_10@

我不明白如何在Android上设置这样的配置,任何人都可以解释一下?

解决方法 目前,Dagger 2(从v2.0.0开始)没有一些解决方法是不可能的.你可以阅读它 here.

我提出了one workaround,但这需要更改生产代码.

简而言之:

>为@Component提供额外的设置器(例如在Application类中的AndroID setter中)
>测试组件必须扩展生产组件

有关更多信息,请检查两个链接.希望这个问题将在未来版本的匕首2中得到解决.

总结

以上是内存溢出为你收集整理的android – 在使用Dagger2时创建测试依赖项全部内容,希望文章能够帮你解决android – 在使用Dagger2时创建测试依赖项所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1133439.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存