Android测试分片 [英] Android Test Sharding

查看:110
本文介绍了Android测试分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释什么是android中的测试分片意味着完成吗? 而且,如果有人可以分享任何教程,将非常有帮助.

Can anyone explain what is test sharding in android mean to accomplish? And if someone could share any tutorial would be really helpful.

碎片"一词表示整体的一小部分.分片是如何在仅一个数字的基础上执行的,我应该在什么基础上指定shardIndex?

The word shard means a small part of a whole. How does sharding is performed on the basis of just a number, and on what basis should I specify the shardIndex?

与开发人员文档中的定义相同.

Definition as in developer docs.

测试分片

测试运行器支持将一个测试套件拆分为多个 分片,因此您可以轻松运行属于同一分片的测试 在同一个Instrumentation实例下一起作为一个组.每个 分片由索引号标识.运行测试时,使用-e numShards选项指定要创建的单独分片的数量 和-e shard index选项指定要运行哪个分片.

The test runner supports splitting a single test suite into multiple shards, so you can easily run tests belonging to the same shard together as a group, under the same Instrumentation instance. Each shard is identified by an index number. When running tests, use the -e numShards option to specify the number of separate shards to create and the -e shard index option to specify which shard to run.

例如,将测试套件分为10个分片,仅运行 在第二个分片中分组的测试,请使用以下命令:

For example, to split the test suite into 10 shards and run only the tests grouped in the second shard, use the following command:

adb shell am instrument -w -e numShards 10 -e shardIndex 2

推荐答案

通过测试分片,您可以将测试均匀地分组.分片索引是您正在运行的百分比"组.分组的目的是任意的,因为分片的目的是使测试并行化.

Test sharding allows you to evenly divide up your tests into groups. The shard index is which "percentage" group you are running. How the groups are divided is arbitrary as the point of sharding is to parallelize your tests.

例如,假设您要运行60个测试,每个测试需要1分钟才能完成.如果要在单个设备上运行此程序,则将花费一个小时来运行所有测试.现在,假设您想通过在一台设备上同时运行一半测试而另一台设备同时运行另一半测试来加快测试速度,总共只需要30分钟.

For example, lets say you have 60 tests to run and each tests takes 1 minute to complete. If you were to run this on a single device it would take one hour to run all tests. Now lets say you'd like to speed up your tests by running half the tests on one device and the other half on another device at the same time thus taking only 30 minutes in total.

您可以通过并行运行以下ADB命令来做到这一点.

You can do this by running the following ADB commands in parallel.

adb -s DEVICE_1_SERIAL shell am instrument -w -e numShards 2 -e shardIndex 0 > device_1_results // Runs first half of the tests
adb -s DEVICE_2_SERIAL shell am instrument -w -e numShards 2 -e shardIndex 1 > device_2_results // Runs second half of the tests

您现在已经在30分钟内运行了全部60项测试,只需将负载平均分配到两个设备上,就可以处理结果了.

You now have run all 60 tests in only 30 minutes by spreading the load evenly to two devices and can now process the results.

要详细了解其工作原理,请查看其中的ShardingFilter https://android.googlesource.com/platform/frameworks/testing/+/2fe8aed7542ee05ce504d69656475d1948e9c5b2/androidtestlib/src/com/android/test/runner/TestRequestBuilder.java

For the nitty gritty on how it works, look at the ShardingFilter inside of https://android.googlesource.com/platform/frameworks/testing/+/2fe8aed7542ee05ce504d69656475d1948e9c5b2/androidtestlib/src/com/android/test/runner/TestRequestBuilder.java

这篇关于Android测试分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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