Issue
I wrote a test using FragmentScenario:
@Test
fun test() {
launchFragmentInContainer<MyFragment>(Bundle().apply { putParcelableArray(MY_DATA, getMyData()) })
// checks here
}
And I get following error:
Error inflating class com.google.android.material.tabs.TabLayout
And I get the error only when I launch my test (the app works)
I tried to add androidTestImplementation "com.google.android.material:material:1.0.0" to androidTestImplementation but it didn't help
What can I do to fix that?
Solution
The default theme for the activity FragmentScenario launches has a parent theme of android:Theme.WithActionBar - not the MaterialComponents theme that TabLayout requires.
You should pass in the theme that you want to use.
For example, assuming your app has a theme declared as such:
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
You'd use:
launchFragmentInContainer<MyFragment>(
Bundle().apply { putParcelableArray(MY_DATA, getMyData()) },
R.style.AppTheme)
Answered By - ianhanniballake
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.