I had the same problem and solved it by using IntentsTestRule
instead of ActivityTestRule
. IntentsTestRule
is a subclass of ActivityTestRule
. Set up your @Rule
which creates the activity like so:
@Rule
public IntentsTestRule<MyActivity> mActivity = new IntentsTestRule<MyActivity>(MyActivity.class) {
@Override
protected Intent getActivityIntent() {
...
}
};
See the following project for more information:
https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsBasicSample