Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock Dagger activity object graphs?

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.

like image 217
Julian A. Avatar asked Oct 20 '22 19:10

Julian A.


1 Answers

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

like image 132
Eugen Martynov Avatar answered Nov 01 '22 11:11

Eugen Martynov