vendredi 28 août 2015

How can I replace Activity scoped dependencies with mocks using Dagger2

I have a scoped dependency in my Activity and I want to test that activity with some mocks. I have read about different approach that suggest to replace Application component with a test component during the test, but what I want is to replace the Activity component.

For example, I want to test the Activity against mock presenter in my MVP setup.

I believe that replacing component by calling setComponent() on Activity will not work, because Activity dependencies already injected via filed injection. so during the test, real object will be used.

How can I resolve this issue? What about Dagger1? Is it has the same issue?

Aucun commentaire:

Enregistrer un commentaire