对类com.google.android.material.tabs.TabLayout进行内部碎片场景测试时出错

对类com.google.android.material.tabs.TabLayout进行内部碎片场景测试时出错,android,kotlin,android-testing,androidx,android-fragmentscenario,Android,Kotlin,Android Testing,Androidx,Android Fragmentscenario,我使用片段场景编写了一个测试: @Test fun test() { launchFragmentInContainer<MyFragment>(Bundle().apply { putParcelableArray(MY_DATA, getMyData()) }) // checks here } 我只有在启动测试时才会出现错误(应用程序正常工作) 我试图将androidTestImplementation“com.google.a

我使用
片段场景
编写了一个测试:

@Test
    fun test() {
        launchFragmentInContainer<MyFragment>(Bundle().apply { putParcelableArray(MY_DATA, getMyData()) })
        // checks here
    }
我只有在启动测试时才会出现错误(应用程序正常工作) 我试图将androidTestImplementation
“com.google.android.material:material:1.0.0”
添加到androidTestImplementation中,但没有任何帮助


我能做些什么来解决这个问题?

活动
碎片场景
启动的默认主题有一个父主题
android:theme。WithActionBar
-而不是
TabLayout
所需的
MaterialComponents
主题

你应该传入你想要使用的主题

例如,假设您的应用程序已声明主题:

<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>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
您可以使用:

launchFragmentInContainer<MyFragment>(
    Bundle().apply { putParcelableArray(MY_DATA, getMyData()) },
    R.style.AppTheme)
launchFragmentInContainer(
Bundle().apply{putParcelableArray(MY_DATA,getMyData())},
R.style.AppTheme)

活动
碎片场景
启动的默认主题有一个父主题
android:theme。WithActionBar
-而不是
表格布局
所需的
材质组件
主题

你应该传入你想要使用的主题

例如,假设您的应用程序已声明主题:

<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>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
您可以使用:

launchFragmentInContainer<MyFragment>(
    Bundle().apply { putParcelableArray(MY_DATA, getMyData()) },
    R.style.AppTheme)
launchFragmentInContainer(
Bundle().apply{putParcelableArray(MY_DATA,getMyData())},
R.style.AppTheme)