【问题标题】:Android weird test shardingAndroid奇怪的测试分片
【发布时间】:2018-01-07 04:42:30
【问题描述】:

我正在 Android 上尝试测试分片,结果很奇怪:

+ adb -s emulator-5580 shell am instrument -e numShards 2 -e shardIndex 0 -e class com.package.etc.automation.Tests.SanityTest.SanityTest -w com.package.etc.test/android.support.test.runner.AndroidJUnitRunner

com.package.etc.automation.Tests.SanityTest.SanityTest:..........

Time: 306.578

OK (10 tests)


+ adb -s emulator-5582 shell am instrument -e numShards 2 -e shardIndex 1 -e class com.package.etc.automation.Tests.SanityTest.SanityTest -w com.package.etc.test/android.support.test.runner.AndroidJUnitRunner

com.package.etc.automation.Tests.SanityTest.SanityTest:......................

Time: 645.723

OK (22 tests)

如您所见,adb 将测试分成两个不均匀的组。第二个的测试数量是第一个的两倍,执行时间是第一个的两倍。如果你问我,这不是最好的并行性。

是否有可能控制测试的分布,或者至少强制 adb 平均拆分测试?

【问题讨论】:

    标签: android junit adb sharding instrumentation


    【解决方案1】:

    让我们追踪它。

    当测试套件是 started 时,TestRequestBuilder 是基于 JUnit Filters 构建的。 ShardingFilter 是其中之一,is added。添加它意味着先前添加的 Filter"intersected" 和新的 - 方法 public boolean shouldRun(Description description) 被调用。如果你看的话,更有可能是这个片段:

    if (description.isTest()) {
        return (Math.abs(description.hashCode()) % mNumShards) == mShardIndex;
    }
    

    替换为您的数字 (numShards=2),您会注意到,这只是一个奇偶校验测试。统计上可能会发生,生成的 HashCode 奇偶校验分布不是 50%。此外,当您的测试类上的某些测试被忽略、禁用并与启用的测试交织时,您甚至可以更干扰特定方法hashcodeJunit DescriptionuniqueId 是从方法和类名生成的)。

    这只是统计问题。正如您在this answer 中看到的那样:

    如何划分组是任意的

    【讨论】:

    • 不错的下拉菜单,先生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 2011-12-16
    • 2017-06-01
    • 2016-08-14
    • 2014-04-13
    • 1970-01-01
    相关资源
    最近更新 更多