问题描述
在阅读文档的匕首2我无法找到一个简单的方法构建的测试应用程序时提供的依赖。我发现的唯一的线索是这样的:
While reading the docs for dagger 2 I cannot find an easy way to provide a dependency when building an app for testing. The only clue I've found is this:
匕首2不支持替代。模块
覆盖简单的测试假货可以创建
该模块的一个子类来模拟该行为。
使用覆盖,并依靠依赖注入模块
应被分解,使得被覆盖的模块代替
再presented作为一个选择两个模块之间。
我不明白我怎么会建立这样的配置在Android上,任何人都可以解释一下吗?
I don't understand how I would set up such a configuration on Android, anyone can explain?
推荐答案
这是没有一些解决方法目前不可能用匕首2(V2.0.0作为的)。你可以阅读一下这里 但是这需要改变生产code。
I've proposed one workaround but this requires changes to the production code.
在短:
- 为
@Component
提供额外的制定者(例如在应用
类的Android二传手) - 测试组件必须扩大生产组件
- provide additional setter for
@Component
(e.g. in Android setter inApplication
class) - test component must extend the production component
有关详细信息,请检查这两个环节。希望这个问题将在2匕首的未来版本中得到解决。
For more information please check both links. Hope this issue will be addressed in future versions of Dagger 2.
这篇关于使用Dagger2当创建依赖性测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!