fragmentScenario Espresso tests of Fragments in Dynamic feature modules

265 views Asked by At

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.

1

There are 1 answers

0
Allan Veloso On

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://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>

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.