自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Tradefed 架构
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分介绍 Tradefed 的内部构件以及这些构件的关系。如需了解详情,请参阅链接的子页面。
测试配置
Tradefed 中的测试配置采用 XML 格式进行描述。了解配置的结构是运行和自定义测试的关键。
TF 配置的结构
全局 TF 配置
全局配置文件是一种特殊的 Tradefed XML 配置,在 Tradefed 通过 TF_GLOBAL_CONFIG
环境变量启动时加载。它会加载与 Tradefed 实例范围相关的对象,这些对象将影响自动化测试框架的整体行为。
全局配置详情
密钥库
密钥库允许将来自某个密钥库的命令行选项注入 Tradefed,以避免直接在命令行上引用相应值。这可用于在命令行中隐藏密码,方法是直接从密钥库检索密码。
密钥库详情
设备管理器
设备管理器负责跟踪正在运行的 Tradefed 实例上的设备状态。它会监控分配状态和在线状态等方面。
测试命令调度程序
Tradefed 中的测试命令调度程序接受要运行的命令、将这些命令与设备关联,并启动测试调用。
build 提供程序
任何测试调用的第一步都是调用 build 提供程序。它会下载设置和运行测试所需的资源(build 映像、测试 APK 等)。它还会在将传递给测试的 BuildInfo
对象中引用这些资源。本地可用的资源也可以链接在 BuildInfo
对象中。
目标准备器和清理器
目标准备器提供了一些可选操作,用于将被测目标配置为某种状态,例如刷写设备、设置某些属性以及连接到 Wi-Fi。
测试运行程序
Tradefed 中的测试运行程序是指负责实际测试执行的对象。不同的测试运行程序以不同的方式驱动测试执行;例如,插桩测试运行程序将与 JUnit 测试运行程序截然不同。
结果报告程序
Tradefed 中的结果报告程序是指会将结果发送到特定目的地的对象。每个实现通常专用于不同的结果后端。结果报告程序负责将 Tradefed 结果格式转换为目标格式。
借助这种灵活的设计,任何测试都能向任何结果目标报告结果,而且还能以隔离的方式轻松添加更多测试。
指标收集器
指标收集器是 Tradefed 中的一个特殊对象,与测试执行正交。它允许在测试生命周期的不同时间点(例如,测试开始时间和测试结束时间)收集信息。由于收集器独立于测试本身,因此可以交换、添加和移除这些时间点,而不必更改测试本身。
主机范围的设置
本部分介绍适用于完整 Tradefed 实例运行的设置。这些选项会影响整个自动化测试框架的行为,以便适应不同的环境,例如在受限网络中。
其他功能
下面几部分介绍 Tradefed 而非 Tradefed 对象的一般用法。
Tradefed 分片
如果测试语料库很大或执行需要很长时间,可以将其拆分到多部设备上。我们将这种拆分称为“分片”。本部分介绍分片的工作原理及其配置方式。
分片详情
使用 SL4A
Tradefed 支持 Android 的脚本层,即 SL4A;这是一个自动化工具集,用于以独立于平台的方式调用 Android API。
SL4A 与 Tradefed 配合使用详情
动态 @option 下载
在某些情况下,测试或某项特定操作所需的文件不在本地。此功能允许 Tradefed 从远程位置获取这些文件,而无需通过 build 提供程序。
动态 @option 下载
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-07。
[[["易于理解","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-04-07。"],[],[],null,["# Tradefed architecture\n\nThis section describes the internals of Tradefed and their relationships. See\nthe linked subpages for more details.\n\nTest configurations\n-------------------\n\nTest configurations in Tradefed are described in an XML format. Understanding\nthe structure of the configuration is key to running and customizing tests.\n\n### Structure of TF configurations\n\n- [High-level structure](/docs/core/tests/tradefed/architecture/xml-config)\n- [Templates and includes](/docs/core/tests/tradefed/architecture/xml-config/template-include)\n- [Configuration object](/docs/core/tests/tradefed/architecture/xml-config/config-object)\n\n### Global TF configurations\n\nA Global Configuration file is a special Tradefed XML configuration that is\nloaded when Tradefed starts via the `TF_GLOBAL_CONFIG` environment variable. It\nloads objects related to the Tradefed instance scope that will affect the\noverall harness behavior.\n\n[Global Configuration details](/docs/core/tests/tradefed/architecture/advanced/global-config)\n\n### Keystore\n\nKeystore allows injection of command line options to Tradefed coming from a\nkeystore in order to avoid referencing the value directly on the command line.\nThis can be used to hide passwords from the command line by retrieve passwords\nfrom the keystore directly.\n\n[Keystore details](/docs/core/tests/tradefed/architecture/advanced/keystore)\n\nDevice manager\n--------------\n\nThe device manager is responsible for keeping track of the state of devices on a\nrunning instance of Tradefed. Aspects such as allocation status and online\nstatus are monitored.\n\n- [Device states](/docs/core/tests/tradefed/architecture/device-manager)\n- [Device allocation](/docs/core/tests/tradefed/architecture/device-manager/device-allocation)\n- [Device detection sequence](/docs/core/tests/tradefed/architecture/device-manager/device-detection)\n\nTest command scheduler\n----------------------\n\nThe test command scheduler in Tradefed takes commands to run, associates them\nwith devices, and starts a test invocation.\n\n- [Test command life cycle](/docs/core/tests/tradefed/architecture/advanced/command-scheduler)\n\nBuild provider\n--------------\n\nBuild provider is the first step of any test invocation. It downloads resources\nneeded to set up and run the tests (build images, test APKs, and more.). It also\nreferences them in a `BuildInfo` object that will be passed to the test. Locally\navailable resources can also be linked in the `BuildInfo` object.\n\n- [Build provider details](/docs/core/tests/tradefed/architecture/build-provider)\n- [Build info details](/docs/core/tests/tradefed/architecture/build-provider/build-info)\n\nTarget preparer and cleaner\n---------------------------\n\nTarget preparer offers optional actions that can be taken to configure the\ntarget under test into a certain state, for example flashing the device, setting\ncertain properties, and connecting to Wi-Fi.\n\n- [Add a new target preparer/cleaner](/docs/core/tests/tradefed/architecture/target-preparer)\n- [Add a new multi target preparer](/docs/core/tests/tradefed/architecture/target-preparer/multi-target)\n\nTest runner\n-----------\n\nA test runner in Tradefed refers to the object responsible for the actual test\nexecution. Different test runners drive test execution in different ways; for\nexample, an instrumentation test runner will be very different from a JUnit test\nrunner.\n\n- [Test runner structure](/docs/core/tests/tradefed/architecture/advanced/test-runner)\n\nResult reporter\n---------------\n\nResult reporter in Tradefed refers to the object that will send the results to a\nparticular destination. Each implementation is usually specialized for different\nresult back-ends. And the result reporter is in charge of converting the\nTradefed results format into the destination format.\n\nThis flexible design allows any test to report to any of the results\ndestinations and to easily have more tests added in an isolated way.\n\n- [Add a result reporter](/docs/core/tests/tradefed/architecture/result-reporter)\n- [Result reporter and logs](/docs/core/tests/tradefed/architecture/result-reporter/log-reporter)\n- [Result reporter summary](/docs/core/tests/tradefed/architecture/result-reporter/summary)\n\nMetrics collector\n-----------------\n\nMetrics collector is a special object in Tradefed, orthogonal to the test\nexecution. It allows collection of information at different points of the test\nlifecycle (for example, test start, test end). Since the collector is decoupled\nfrom the test itself, the points can be swapped, added, and removed without\nhaving to change the test itself.\n\n- [Host-driven metrics collectors](/docs/core/tests/tradefed/architecture/metrics-collector)\n- [Device side metrics collectors](/docs/core/tests/tradefed/architecture/metrics-collector/device-collector)\n\nHost-wide setup\n---------------\n\nThis section describes setups that are applicable to a full Tradefed instance's\nrunning. These options affect the behavior of the harness as a whole in order to\nadapt to different environments, for example being in a restricted network.\n\n- [Global Configuration](/docs/core/tests/tradefed/architecture/advanced/global-config)\n- [Host options](/docs/core/tests/tradefed/architecture/host-setup/host-options)\n\nAdditional features\n-------------------\n\nThe following sections describe general usage of Tradefed rather than Tradefed\nobjects.\n\n### Tradefed sharding\n\nWhen the test corpus is large or takes a long time to execute, it's possible to\nsplit it across several devices. We refer to this split as *sharding*. This\nsection describes how sharding works and how it is configured.\n\n[Sharding details](/docs/core/tests/tradefed/architecture/advanced/sharding)\n\n### Using SL4A\n\nTradefed supports the scripting layer for Android, SL4A; this is an automation\ntoolset for calling Android APIs in a platform-independent manner.\n\n[SL4A with Tradefed details](/docs/core/tests/tradefed/architecture/advanced/scripting-sl4a)\n\n### Dynamic @option download\n\nIn some cases, the files needed by a test or some particular operation are not\navailable locally. This feature allows Tradefed to get these files from a remote\nlocation without going through a build provider.\n\n[Dynamic @option download](/docs/core/tests/tradefed/architecture/advanced/protocols-global-config)"]]