connectedAndroidTest on multiple emulators

自闭症网瘾萝莉.ら 提交于 2019-12-10 12:34:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42588457/connectedandroidtest-on-multiple-emulators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!