Skip to content Skip to sidebar Skip to footer

How Can I Test Activity Based On Actionbaractivity (from Android.support.v7.app) Using Androidunittestcase Class?

Sorry for my English. I use Android Studio. To learn how to create tests in Android Studio I used this SO post All tests are in the same Android App Module where the source. The s

Solution 1:

The problem lies in the Context that is used to create the Activities. As the test context is not themed, you must do it yourself.

public void setUp() throws Exception {
    super.setUp();
    ContextThemeWrapper context = new ContextThemeWrapper(getInstrumentation().getTargetContext(), R.style.AppTheme);
    setActivityContext(context);
    activity = startActivity(new Intent(Intent.ACTION_MAIN), null, null);
}

Post a Comment for "How Can I Test Activity Based On Actionbaractivity (from Android.support.v7.app) Using Androidunittestcase Class?"