自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Tradefed 架構
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節說明 Tradefed 的內部元件及其關係。詳情請參閱連結的子頁面。
測試設定
Tradefed 中的測試設定會以 XML 格式說明。瞭解設定的結構是執行及自訂測試的關鍵。
TF 設定的結構
全域 TF 設定
全域設定檔是一種特殊的 Tradefed XML 設定,會在 Tradefed 透過 TF_GLOBAL_CONFIG
環境變數啟動時載入。它會載入與 Tradefed 執行個體範圍相關的物件,這些物件會影響整體整合行為。
全域設定詳細資料
KeyStore
可讓您將來自 Keystore 的指令列選項注入 Tradefed,以免直接在指令列上參照該值。這可用於直接從金鑰庫擷取密碼,藉此隱藏指令列中的密碼。
KeyStore 詳細資料
裝置管理員
裝置管理員負責追蹤 Tradefed 執行中例項的裝置狀態。系統會監控分配狀態和上線狀態等。
測試指令排程器
Tradefed 中的測試指令排程器會取得要執行的指令,將指令與裝置建立關聯,並啟動測試叫用作業。
建構提供者
建構提供者是任何測試叫用作業的第一步。它會下載設定及執行測試所需的資源 (建構映像檔、測試 APK 等)。並在將傳遞至測試的 BuildInfo
物件中參照這些值。您也可以在 BuildInfo
物件中連結本機可用的資源。
目標準備工具和清理工具
目標準備工具提供可選動作,可將測試中的目標設為特定狀態,例如閃燈裝置、設定特定屬性和連線至 Wi-Fi。
測試執行程式
Tradefed 中的測試執行程式是指負責實際執行測試的物件。不同的測試執行程式會以不同方式執行測試,例如檢測設備測試執行程式與 JUnit 測試執行程式就大不相同。
結果回報工具
Tradefed 中的結果回報器是指會將結果傳送至特定目的地的物件。每個實作通常都專門針對不同的結果後端。而結果回報器負責將 Tradefed 結果格式轉換為目標格式。
這種彈性設計可讓任何測試回報至任何結果目的地,並輕鬆以隔離方式新增更多測試。
指標收集器
指標收集器是 Tradefed 中的特殊物件,與測試執行作業平行。可在測試生命週期的不同時間點 (例如測試開始、測試結束) 收集資訊。由於收集器已與測試本身解耦,因此您可以換用、新增和移除測試點,而無須變更測試本身。
全主機層級設定
本節說明適用於 Tradefed 完整執行例項的設定。這些選項會影響整體測試架構的行為,以便適應不同的環境,例如受限制的網路。
其他功能
以下各節說明 Tradefed 的一般用法,而非 Tradefed 物件。
Tradefed 分割
如果測試語料庫很大或執行時間很長,您可以將其拆分到多部裝置上。我們將這種分割稱為「分割」。本節說明分割作業的運作方式和設定方式。
分割詳細資料
使用 SL4A
Tradefed 支援 Android 的 Scripts 層,也就是 SL4A;這是一組自動化工具,可以不依賴平台的方式呼叫 Android API。
SL4A 搭配 Tradefed 詳細資料
動態 @option 下載
在某些情況下,測試或某些特定作業所需的檔案無法在本機使用。這項功能可讓 Tradefed 從遠端位置取得這些檔案,而無須透過建構供應器。
動態 @option 下載
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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)"]]