googlesamples / android-testing-templates

Apache License 2.0
1.96k stars 303 forks source link

Splits option breaks test module #24

Open MartinDevi opened 7 years ago

MartinDevi commented 7 years ago

I had an issue when trying to set up a testing module, based on the model provided in module-flavor1-androidTest-only. I eventually realized that it was due to the fact that I had ABI splits set up in my application, leading the connectedAndroidTest task to fail.

I was able to reproduce the issue in this project by adding the following snippet inside the android block of the app module's build.gradle file:

splits.abi {
    enable true
    reset()
    include 'armeabi', 'armeabi-v7a'
}

By running ./gradlew module-flavor1-androidTest-only:connectedDebugAndroidTest, I get the same exception as in my application.

> Expected configuration ':module-flavor1-androidTest-only:testTarget-metadata' to contain exactly one file, however, it contains no files.

By debugging Gradle, I found that the error occurs because TestApplicationData#getTestedApks handles modules with splits differently, since testedApkFiles.size() > 1 && splitSelectExe != null evaluates to true. The code then fails at TestApplicationData#loadMetadata.

I ended up disabling splits in my app, only when I'm running the instrumentation tests in this module. Any idea for a better workaround in the Gradle setup? Or is this just a bug in the Android Gradle Plugin which should be reported to their development team?