Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connectedAndroidTest on multiple emulators

Background

I want to run my Android Instrumented tests on Jenkins on different emulators. Say I have 100 tests and 4 emulators, I want to run 25 tests on each.

I perform ./gradlew connectedDebugAndroidTest in Jenkins Pipeline's parallel for 4 emulators

stage('Instrumented Tests') {
    parallel(
            emu1: {
                 runInstrumentedTestOnEmu(...)
            },
            emu2: {
                 runInstrumentedTestOnEmu(...)
            }
            ...
    )
}

connectedDebugAndroidTest will spawn other commands in order to setup the environment for running instrumented tests.

...
:app:transformNativeLibsWithMergeJniLibsForDebugAndroidTest
:app:processDebugAndroidTestJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebugAndroidTest
:app:validateSigningDebugAndroidTest
:app:packageDebugAndroidTest
:app:assembleDebugAndroidTest
:app:connectedDebugAndroidTest

And when environment is ready then it performes :app:connectedDebugAndroidTest which will start running tests on emulator.

I do not want to run these procedure for all my parallel calls (in this case it would be 4 of them), because obviously I'm doing the exact same job multiple times. Theoretically, the best option would be to perform setup before parallel and when everything is ready for running tests, then go into parallel step and start tests on each emulator.

Question

Is it possible to perform all the pre-setup steps of connectedDebugAndroidTest without performing itself?

Additionally, if I run connectedDebugAndroidTest parallel on 4 emulators the build crashes, because gradle tries to read a file from intermediate directory, when other parallel build has already removed that file, which results in crash.

You can view this test project in github with setup mentioned above.

like image 584
azizbekian Avatar asked Mar 03 '17 21:03

azizbekian


1 Answers

Is it possible to perform all the pre-setup steps of connectedDebugAndroidTest without performing itself?

Yes, you can run assembleDebugAndroidTest, which as your build log shows, is the last prerequisite to running the device tests. Running that will build both the app and test APKs.

Though AFAIK, there isn't a way of sharding your tests across multiple emulators when using Gradle — you would have to install both of the APKs onto each emulator and use adb shell am instrument with the numShards and shardIndex options.

like image 174
Christopher Orr Avatar answered Nov 14 '22 12:11

Christopher Orr