使用Dagger2当创建依赖性测试依赖性、测试

由网友(叚)分享简介:在阅读文档的匕首2我无法找到一个简单的方法构建的测试应用程序时提供的依赖。我发现的唯一的线索是这样的:While reading the docs for dagger 2 I cannot find an easy way to provide a dependency when building an app f...

在阅读文档的匕首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作为一个选择两个模块之间。

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.

我不明白我怎么会建立这样的配置在Android上,任何人都可以解释一下吗?

I don't understand how I would set up such a configuration on Android, anyone can explain?

推荐答案

这是没有一些解决方法目前不可能用匕首2(V2.0.0作为的)。你可以阅读一下这里 。

This is currently impossible with Dagger 2 (as of v2.0.0) without some workarounds. You can read about it here.

我已经提议one解决方法但是这需要改变生产code。

I've proposed one workaround but this requires changes to the production code.

在短:

@Component 提供额外的制定者(例如在应用类的Andr​​oid二传手)测试组件必须扩大生产组件 provide additional setter for @Component (e.g. in Android setter in Application 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.

阅读全文

相关推荐

最新文章