トラッキング コード

1/21/2015

IllegalStateException at ActivityUnitTestCase with ActionBarActivity

I need to do ActivityUnitTestCase which activity is extends ActionBarActivity.
However, I get the following exception.

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)


If call startActivity, Context does not have Theme.AppCompat...
So, We need to call setActivityContext() due to set Context with theme.
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        Context context = getInstrumentation().getTargetContext();
        ContextThemeWrapper contextTheme = new ContextThemeWrapper(context, R.style.AppTheme);
        setActivityContext(contextTheme);
        startActivity(new Intent(), null, null);
    }

No comments:

Post a Comment