android - How to generate DaggerComponent class in the test/java folder? -
i'm new dagger 2 , i'm working on using dagger 2 unit tests. test presenter , mock of datasources(server connection, sharedpreferences).
sharedpreferences have sharedpreferencescomponent
in main
folder , sharedpreferencescomponentfake
in test/java
folder. problem dagger can't generate daggersharedpreferencescomponentfake
therefore can't inject sharedpreferencesfake
instead sharedpreferences. how can set dagger generate daggersharedpreferencesfake class , or using dagger 2 in wrong way
why not use mockito , mock sharedpreferencescomponent
mockito.when(sharedpreferencescomponent.yourmethod(any(string.class))) .thenreturn(yourwanteroutput);
this make faking classes unnecessary , code cleaner.
Comments
Post a Comment