Override resource files in Android instrumented tests

72 views Asked by At

Disclaimer: related but different from this, this and this.

I would like to point AndroidManifest.xml to an xml resource file like this:

    <application
        [...]
        android:networkSecurityConfig="@xml/network_security_config">

Where the "normal" build gets it from app/src/main/res/xml/network_security_config.xml (note the main) and the instrumented test build gets it from app/src/androidTest/res/xml/network_security_config.xml (note the androidTest).

Note that the xml file looks like this in this case, but I think it's irrelevant:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="false" />
</network-security-config>

Unfortunately that doesn't seem to work: the resource in "androidTest/" is just ignored. However, I can override the file in debug builds by putting it into app/src/debug/res/xml/network_security_config.xml. While that "does the job", it's not exactly what I want: it overrides the file for debug builds, and I want to override the file for the instrumented tests.

Is there any way I could tell Android to use my "androidTest/" resources when building instrumented tests?

0

There are 0 answers