I would like to add layout xml files into my androidTest
folder to be used only for testing.
I added res/layout
folder to androidTest
It is tricky to add xml resources to androidTest
.
Android Instrumentation tests create another APK to run the tests against your original application. Although you can access your Context
and objects from your main application, you cannot modify the generated APK file of your app.
That means you cannot put additional layout xml to your original application from tests that are in the androidTest
folder.
Alternatively,
buildType
called espresso
.espresso
folder where you can put any java or Android resource you want to add.
AndroidManifest
there.testBuildType 'espresso'
Your build.gradle
should look like this:
android {
testBuildType 'espresso'
buildTypes {
espresso.initWith(buildTypes.release)
}
}
dependencies {
espressoCompile 'somedependency' // you can even have special dependencies
}
When you run your espresso tests around that flavor, you will have an access to additional layout xml files you added.
Should look like this: