I need to run Android tooled test on StarterActivity . Here's how to do it.
public class StarterActivity extends BaseActivity<ActivityStarterBinding> { @Inject protected StarterViewModel starterViewModel; @Override public int getContentView() { return R.layout.activity_starter; } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getApplicationComponent().inject(this); }
And I call the starterViewModel method on onStart.
starterViewModel is entered through the constructor:
public class StarterViewModel { private final AuthDataModel authDataModel; @Inject public StarterViewModel(AuthDataModel authDataModel) { this.authDataModel = authDataModel; } @NonNull public Single<Boolean> isUserLoggedIn() { return authDataModel.isUserLoggedIn(); } }
I found this really nice Android testing approach using Dagger 2, Mockito, and the JUnit custom rule . But I need to add the @Provide method. And the application component will become a “God component” with dependencies on a group of modules (or one “God module”).
How can I make a mistake in the Espresso test without adding the @Provide method and overriding it in the tests?
source share