fragmentScenario Espresso tests of Fragments in Dynamic feature modules
Asked Answered
N

1

7

Has anyone figured out how to test fragments in Dynamic feature modules in isolation using fragmentScenario Espresso tests where the app's Activity is in a base module.

I have overcome several issues such as complaints about the style not being Theme.Appcompat and Android Studio not running, but now the withId is complaining at runtime that it can't find an R.id in the fragment's layout.

Nebula answered 12/11, 2019 at 22:42 Comment(5)
same problem here. did you ever manage to solve it? You can write the answer to your own question. (not exactly the R.id problem but basically hiting the button won't change my navigation)Borscht
No I never figured it out. This is one of several issues that caused us to give up on using dynamic feature modules all together. In my opinion the advantages are not worth the many complications that they cause. Except maybe for niche use cases like games with large downloadable extras.Nebula
Well I am still stuck between "can't find the FragmentScenarioEmptyActivityTheme". and "no tests to run" :\ This is really horribleSotted
@Sotted I solved the FragmentScenarioEmptyActivityTheme, besides adding ` debugImplementation("androidx.fragment:fragment-testing:1.4.1") ` to your dynamic feature module you also has to add it to your app module.Quell
If anyone is still interesting, I think the trick is make the testing apk work as a monolithic apk, i.e.: enforce on tests the fusion that happens in devices with API < 20. I am trying this approach but my mac silicon does not run api < 20 for a quick test, so it will take a while to find a solution.Quell
Q
0

I solve my problems with instrumented tests in dynamic modules by creating an AndroidManifest.xml in the folder src/debug of the dynamic module and placing:

<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://mcmap.net/q/361227/-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>

This will make the application works as monolithic .apk on tests which is great for local and CI/CD small intrumentation tests.

If you need to test the delivery itself in a end-to-end test like suggested here, I am not sure if this will have a impact, but if it has you can still create a flavor for your end-to-end test that override again the manifest.

Quell answered 13/6, 2022 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.