Espresso, Dagger2 set ViemodelProvider.Factory on BaseActivity

后端 未结 4 1646
[愿得一人]
[愿得一人] 2021-01-11 09:19

I have an abstract AccountRequiredActivity that looks like this (and works fine):

public abstract class AccountRequiredActivity extends LifecycleActivity {
         


        
4条回答
  •  星月不相逢
    2021-01-11 10:24

    Try to override dagger module for provide ViewModelProvider.Factory.

    • change testInstrumentationRunner 'com.eusecom.attendance.MockTestRunner' in app/build.gradle

    • call MockYourApplication.class in MockTestRunner

    • create new Mock dagger component in your MockYourApplication.class

    • before run testActivity override dagger component and module

    Watch example https://github.com/eurosecom/Attendance/blob/master/app/src/androidTest/java/com/eusecom/attendance/DgAeaActivityTest.java

    I have not used new dagger 2.11 with AndroidInjector ( i have used older dagger2 pattern ) but may be it helps.

提交回复
热议问题