自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
通过 Tradefed 运行测试
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Tradefed 中测试的执行由测试运行程序来执行,这些测试运行程序允许控制 Android 设备以执行必要的测试步骤。 请依次按照这些部分中的说明操作。
1. 编写新的测试运行程序
在这里,您将学习关于编写新 Tradefed 测试运行程序的基础知识。如果您计划支持全新类型的测试,并且需要从头开发新的运行程序,这会特别有用。
有关说明,请参阅编写 Tradefed 测试运行程序。
2. 编写可分片测试运行程序
您还可以学习如何使您的测试运行程序可分片。可分片测试运行程序允许基础架构将完整的测试执行分布在多个设备上(并置或不并置)。当测试语料库很大并且您希望并行化执行和加速完成时,这会很有用。
有关步骤,请参阅编写分片 IRemoteTest 测试运行程序。
3. 编写主机驱动的测试
主机驱动的测试是一种常见的用例。在这种用例中,测试执行从主机端驱动,并根据测试的需要查询设备。当测试所需的设备操作影响设备状态本身时(例如重新启动设备),这类测试非常有用。
测试运行程序类型可以在 Tradefed 中使用,也可以在通过套件运行测试时使用。
有关说明,请参阅在 Trade Federation 中编写主机驱动的测试。
4. 报告测试中的指标
除了执行结果之外,测试还会报告指标,这种情况十分常见。报告指标的方法有几种,具体采用哪种方法取决于测试运行程序。
有关示例,请参阅报告 Tradefed 测试中的指标或数据。
5. 自动日志收集
某些日志通常用于调试问题,例如:Logcat。因此,Tradefed 提供了一种自动机制以轻松地收集这些日志。
要了解如何使用,请参阅自动收集关于失败测试的日志。
6. 自动重新运行测试
您可以让 Tradefed 自动重试失败的测试或迭代地多次运行某些测试。
如需了解详情,请参阅自动重新运行测试。
7. 重试隔离
您可以让 Tradefed 尝试在两次重试尝试之间隔离测试作业。
如需了解详情,请参阅重试隔离。
8. 编写 shell 测试
请参阅在 Trade Federation 中编写 shell 测试。
请参阅 Trade Federation 中的全局过滤器。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Test through Tradefed\n\nExecution of tests in Tradefed is conducted by *test runners* that allow the\ncontrol of Android *devices* for necessary testing steps. Follow these sections in order.\n\n1. Write a new test runner\n--------------------------\n\nHere you will learn the basics that go into writing a new Tradefed test runner.\nThis is particularly useful if you plan to support a brand new type of test, and\nyou need a new runner to be developed from scratch.\n\nSee [Write a Tradefed test runner](/docs/core/tests/tradefed/testing/through-tf/new-test-runner) for instructions.\n\n2. Write a shardable test runner\n--------------------------------\n\nYou may also learn how to make your test runner shardable. A shardable test\nrunner allows the infrastructure to distribute the full test execution over\nseveral devices (collocated or not). This is useful when the corpus of\ntests is large, and you want to parallelize the execution and speed completion.\n\nSee [Write a sharded IRemoteTest test runner](/docs/core/tests/tradefed/testing/through-tf/sharded-runner) for\nsteps.\n\n3. Write a host-driven test\n---------------------------\n\nHost-driven tests are a common use case where test execution is driven from\nthe host-side and queries the device as needed for the test. This is useful when\ndevice operation required by the test affects the device state itself, for\nexample rebooting the device.\n\nThe test runner type can be used within Tradefed or when running through a\nsuite.\n\nSee [Write a host-driven test in Trade Federation](/docs/core/tests/tradefed/testing/through-tf/host-driven-test) for\ninstructions.\n\n4. Report metrics from tests\n----------------------------\n\nIt's fairly common for a test to report metrics in addition to the execution\nresults. Depending on the test runner, there are several methods to report the\nmetrics.\n\nSee [Report metrics or data from a Tradefed test](/docs/core/tests/tradefed/testing/through-tf/report-metrics) for examples.\n\n5. Automated log collection\n---------------------------\n\nSome logs are commonly used for debugging issues, for example: Logcat. So\nTradefed offers an automated mechanism to collect them easily.\n\nSee [Automated log on failure collection](/docs/core/tests/tradefed/testing/through-tf/log-on-failure) for use.\n\n6. Automatic test retry\n-----------------------\n\nYou may enable Tradefed to automatically retry failures or run some tests\nseveral times in iterations.\n\nSee [Automatic test retry](/docs/core/tests/tradefed/testing/through-tf/auto-retry) for more details.\n\n7. Retry isolation\n------------------\n\nYou may enable Tradefed to attempt to isolate the test execution between retry\nattempts.\n\nSee [Retry isolation](/docs/core/tests/tradefed/testing/through-tf/retry-isolation) for more details.\n\n8. Write a shell test\n---------------------\n\nSee [Write a shell test in Trade Federation](/docs/core/tests/tradefed/testing/through-tf/shell-test).\n\n9. Configure global test filters\n--------------------------------\n\nSee [Global filters in Trade Federation](/docs/core/tests/tradefed/testing/through-tf/global-filters)."]]