我用 Cucumber 和 Espresso 为模块化 Android 项目编写了一个 UI 测试场景。 该项目有一个依赖于基本模块的模块。 当我运行测试时,我在 xml 布局中遇到错误,因为该模块显然无法访问基本模块的资源(仅在测试运行时),例如,包含来自基本模块或自定义视图的布局。
.Feature Enter receiver details > Scenario Outline "Register Person" FAILED
android.view.InflateException: Binary XML file line #9
in [package_name].test:layout/fragment_register_person: Binary XML file line #2
in [package_name].test:layout/toolbar_title:
Error inflating class com.google.android.material.appbar.AppBarLayout Caused by:
android.view.InflateException: Binary XML file line #2
in [package_name].test:layout/toolbar_title:
Error inflating class com.google.android.material.appbar.AppBarLayout
在这种情况下我使用:
<include layout="@layout/toolbar_title" />
和自定义视图:
<com.me.base.view.customview.RtlTextInputLayout
从基本模块导入。 我还补充道:
androidTestImplementation project(path: ':Base')
在当前模块中。
我通过在 Android Studio 终端中执行 Gradle 命令来运行测试:
gradlew myModule:connectedCheck -Pcucumber -Pscenario="Register Person"
我能做什么?
我只需为 launchFragmentInContainer 定义 R.style.Theme :)
launchFragmentInContainer(themeResId = R.style.Theme)