Skip to content Skip to sidebar Skip to footer

You Need To Use A Theme.appcompat Theme --> In Unit Test

I know this topic has been discussed but it is a little different here: App works fine Error is displayed only in unit test Theme is Fine (new created sample project) How to repr

Solution 1:

The following code worked for me -- added to the unit test:

@OverridepublicvoidsetUp(){
    ContextThemeWrappercontext=newContextThemeWrapper(getInstrumentation().getTargetContext(), R.style.AppTheme);
    setActivityContext(context);
}

See also: ActivityUnitTestCase and startActivity with ActionBarActivity

Also possible

Use ActivityInstrumentationTestCase2 instead of ActivityUnitTestCase fixes the issue too.

In addition the "onPause" of the activity isn't called. Which is somehow odd with ActivityUnitTestCase

Solution 2:

Using the new AndroidX libraries this can be solved by passing the theme to the fragment launching method:

valauthDialogScenario= launchFragment<AuthDialog>(themeResId = R.style.AppTheme)

This was the solution in my case.

Post a Comment for "You Need To Use A Theme.appcompat Theme --> In Unit Test"