如何模拟匕首活动对象图? [英] How to mock Dagger activity object graphs?
问题描述
我用匕首在一个Android应用程序提供应用和活动范围图。而我使用Robolectric进行单元测试。我知道,我可以提供Robolectric与配置了覆盖真正的与嘲笑的应用程序对象图的替代应用程序类。但我难倒,如何与活动对象图做同样的,因为标准模式活动对象图是对活动本身来实例化所需的特定活动的匕首模块。任何建议,将不胜AP preciated。
I'm using Dagger in an android app to provide application and activity scope graphs. And I'm using Robolectric for unit-testing. I know that I can provide Robolectric with a substitute Application class that is configured with an application object graph that overrides the real one with mocks. But I'm stumped as to how to do the same with the activity object graphs since the standard pattern for activity object graphs is for the activities themselves to instantiate the activity-specific Dagger module they need. Any suggestions would be greatly appreciated.
推荐答案
请看看我的项目 - 的https: //github.com/emartynov/UrlSetter
Please take a look to my project - https://github.com/emartynov/UrlSetter
您会发现我是如何设法用嘲弄与匕首
在 Robolectric
测试
You will find how I managed to use mocks with Dagger
in Robolectric
tests
这篇关于如何模拟匕首活动对象图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!