Android functional testing with Dagger

前端 未结 3 2269
借酒劲吻你
借酒劲吻你 2021-02-13 21:52

I’m trying to test an Activity with Mockito & Dagger. I have been able to inject dependencies to Activity in my application but when testing the Activity, I have not been a

3条回答
  •  攒了一身酷
    2021-02-13 22:08

    I use Mockito and Dagger for functional testing. The key concept is that your test class inherits from ActivityUnitTestCase, instead of ActivityInstrumentationTestCase2; the latter super-class call onStart() life-cycle method of Activity blocking you for inject your test doubles dependencies, but with first super-class you can handle the life-cycle more fine-grained.

    You can see my working examples using dagger-1.0.0 and mockito for test Activities and Fragments in:

    https://github.com/IIIRepublica/android-civicrm-test

    The project under test is in:

    https://github.com/IIIRepublica/android-civicrm

    Hope this helps you

提交回复
热议问题