android - 动态功能模块中 Fragments 的 fragmentScenario Espresso 测试

标签 android android-studio android-fragments android-espresso dynamic-feature-module

有没有人想出如何使用fragmentScenario Espresso 单独测试动态功能模块中的 fragment ,其中应用程序的 Activity 位于基本模块中。

我已经克服了几个问题,例如提示样式不是 Theme.Appcompat 和 Android Studio 没有运行,但现在 withId在运行时提示找不到 R.id在 fragment 的布局中。

最佳答案

我通过创建 AndroidManifest.xml 来解决动态模块中的仪器测试问题。在文件夹 src/debug动态模块和放置:

<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 小型仪器测试的测试上。
如果您需要在像 suggested here 这样的端到端测试中测试交付本身,我不确定这是否会产生影响,但如果有影响,您仍然可以为您的端到端测试创建一种风格,再次覆盖 list 。

关于android - 动态功能模块中 Fragments 的 fragmentScenario Espresso 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58827785/

相关文章:

android - 未知资源 0 : Robolectric fails with ShareActionProvider when I upgrade to AppCompat

android - 如何在android中处理发送和接收笑脸

android - 找不到 Gradle DSL 方法 : 'android()' opening project in android studio 1. 4

java - android recyclerview viewholder Mediaplayer处理点击问题

java - 暂停 for 循环,除非在 android studio 中单击按钮

android - 如何在MainActivity中保存在不同事务中提交的两个 fragment 的InstanceState?

java - 阻止 FragmentPagerAdapter 立即创建其所有 fragment

java - 在 Android 中创建硬链接(hard link)和符号链接(symbolic link)

android - 在 Android 中使用 checkSelfPermission?

git - 更改 Android Studio/IntelliJ 的 xcrun 开发者路径