How to mock Dagger activity object graphs?

江枫思渺然 提交于 2019-11-30 17:43:40

问题


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.


回答1:


Please take a look to my project - https://github.com/emartynov/UrlSetter

You will find how I managed to use mocks with Dagger in Robolectric tests



来源:https://stackoverflow.com/questions/20308530/how-to-mock-dagger-activity-object-graphs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!