fragmentScenario浓缩咖啡测试动态功能模块中的碎片



有没有人知道如何使用fragmentScenario Espresso测试在动态功能模块中隔离测试片段,其中应用程序的"活动"位于基本模块中。

我已经克服了一些问题,比如抱怨风格不是主题。Appcompat和Android Studio没有运行,但现在withId在运行时抱怨在片段的布局中找不到R.id

我通过在动态模块的文件夹src/debug中创建一个AndroidManifest.xml并放置:来解决动态模块中插入测试的问题

<manifest xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.poc.auth">
<!-- Note that we replace here our delivery from `on-demand` to `install-time` and put on the debug
folder so in tests this performs as a monolithic application and avoid non found
errors. Note also that this manifest need to be in `debug` folder rather
than `androidTest` folder. See https://stackoverflow.com/questions/26244998/androidmanifest-in-androidtest-directory-being-ignored-->

<dist:module
dist:instant="false"
dist:title="Feature Module Auth Test"
tools:node="replace">
<dist:delivery>
<dist:install-time />
</dist:delivery>
<dist:fusing dist:include="true" />
</dist:module>
</manifest>

这将使应用程序在测试中像单片.apk一样工作,这对于本地和CI/CD小型入侵测试非常有用。

如果你需要像这里建议的那样在端到端测试中测试交付本身,我不确定这是否会产生影响,但如果有,你仍然可以为的端到端测试创建一个风格,再次覆盖清单。

最新更新