动态特性模块中Fragments的fragmentScenario Espresso测试

7

有没有人已经解决了如何使用fragmentScenario Espresso测试隔离动态功能模块中的片段,其中应用程序的活动位于基本模块中的问题。

我已经克服了一些问题,比如样式不是Theme.Appcompat和Android Studio无法运行,但现在withId在运行时抱怨它无法在片段的布局中找到R.id


同样的问题在这里。你最终解决了吗?你可以回答自己的问题。(虽然不完全是R.id的问题,但基本上按按钮不会改变我的导航) - coroutineDispatcher
1
不,我从来没有想明白。这是导致我们完全放弃使用动态特性模块的几个问题之一。在我看来,它们带来的优势并不值得它们所引起的许多复杂性。除了像具有大型可下载额外内容的游戏这样的利基用例之外。 - miguel
我还是卡在了“找不到FragmentScenarioEmptyActivityTheme”和“没有可运行的测试”之间 :
这真的很糟糕。
- Alaa
@Alaa 我解决了 FragmentScenarioEmptyActivityTheme 的问题,除了在你的动态功能模块中添加 debugImplementation("androidx.fragment:fragment-testing:1.4.1") 之外,你还需要将其添加到应用程序模块中。 - Allan Veloso
如果有人仍然感兴趣,我认为诀窍在于使测试apk作为一个单体apk工作,即:在测试中强制执行API < 20的设备中发生的融合。我正在尝试这种方法,但我的Mac Silicon无法运行API < 20进行快速测试,因此需要一些时间来找到解决方案。 - Allan Veloso
1个回答

0
我通过在动态模块的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://dev59.com/H18d5IYBdhLWcg3w8WJt>
    
    <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>

这将使应用程序在本地和CI/CD小仪器测试中作为单体.apk运行,非常适用。

如果您需要像此处建议的那样进行端到端测试以测试交付本身,我不确定这是否会产生影响,但如果有影响,您仍然可以为端到端测试创建一个口味,覆盖清单。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接