With a custom instrumentation runner, you can override newApplication and have it instantiate something other than the default application from the manifest.
public class MyRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws Exception {
return super.newApplication(cl, MyCustomEspressoApplication.class.getName(), context);
}
}
Be sure to update testInstrumentationRunner with your custom runner’s name.