vendredi 21 août 2015

Injecting mocks in Tests using Dagger2

Say class A depends on B, and that I want to test class A.

I create a test for class A in which I want to mock B.

Class B is injected into class A using Dagger2 (using a Module and a Component). Meaning, class A has a class member:

@Inject
B mB;

In my test class, I create an instance of A in the setUp() method.

How to I provide the mocked instance of the class B to A?

Aucun commentaire:

Enregistrer un commentaire