Test Android Activity with different Application class

ID : 274357

viewed : 31

Tags : androidandroid-testingandroid-espressoandroid





Top 2 Answer for Test Android Activity with different Application class

vote vote

99

You can subclass the AndroidJUnitRunner with your own runner and override newApplication() with your custom application class.

public class CustomTestRunner extends AndroidJUnitRunner {  @Override public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {     return super.newApplication(cl, CustomTestApplication.class.getName(), context); } } 

Make sure to update your build.gradle with the new runner like this:

testInstrumentationRunner "com.mypackage.name.path.CustomTestRunner"

vote vote

88

Top 3 video Explaining Test Android Activity with different Application class







Related QUESTION?