在多个模拟器上的connectedAndroidTest [英] connectedAndroidTest on multiple emulators

查看:150
本文介绍了在多个模拟器上的connectedAndroidTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我想在Jenkins上的不同模拟器上运行我的Android Instrumented测试.假设我有100个测试和4个仿真器,我想在每个仿真器上运行25个测试.

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.

我在Jenkins Pipeline的并行环境中为4个仿真器执行./gradlew connectedDebugAndroidTest

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

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

connectedDebugAndroidTest将生成其他命令,以便为运行检测的测试设置环境.

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

环境准备就绪后,它将执行:app:connectedDebugAndroidTest,这将开始在模拟器上运行测试.

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

我不想为所有并行调用都运行这些过程(在这种情况下,将是其中的4个),因为显然我多次执行了完全相同的工作.从理论上讲,最好的选择是在parallel之前并且所有内容都可以运行测试的情况下执行设置,然后进入parallel步骤并在每个仿真器上启动测试.

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.

问题

是否可以执行connectedDebugAndroidTest的所有预设置步骤而不执行自身?

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

另外,如果我在4个模拟器上并行运行connectedDebugAndroidTest,则构建崩溃,因为gradle试图从intermediate目录读取文件,而其他并行构建已经删除了该文件,则导致崩溃.

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.

您可以使用上述设置查看此github中的测试项目.

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

推荐答案

是否可以不执行自身而执行connectedDebugAndroidTest的所有预设置步骤?

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

是的,您可以运行assembleDebugAndroidTest,这是构建日志所显示的,这是运行设备测试的最后前提.运行该应用程序将构建应用程序并测试APK.

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.

尽管使用AFAIK,使用Gradle时无法在多个模拟器上分摊测试-您必须将两个APK安装到每个模拟器上,并使用adb shell am instrumentnumShardsshardIndex选项

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.

这篇关于在多个模拟器上的connectedAndroidTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆