自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
透過 Tradefed 進行測試
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 Tradefed 中執行測試的測試執行程式可控制 Android 裝置,執行必要的測試步驟。請依序完成下列各節。
1. 編寫新的測試執行器
您將在這裡學習撰寫新 Tradefed 測試執行程式的基礎知識。如果您打算支援全新類型的測試,且需要從頭開發新的執行程式,這項功能就特別實用。
如需操作說明,請參閱「編寫 Tradefed 測試執行程式」一文。
2. 編寫可分割的測試執行器
您也可以瞭解如何讓測試執行程式可分割。可分割的測試執行程式可讓基礎架構將完整的測試執行作業分散至多部裝置 (不論是否同處一地)。當測試集合體積龐大,且您想並行執行並加快完成速度時,這項功能就很實用。
如需步驟,請參閱「編寫分割的 IRemoteTest 測試執行器」。
3. 編寫主機驅動測試
主機導向測試是常見的用途,其中測試執行作業是由主機端驅動,並視測試需求查詢裝置。當測試所需的裝置操作會影響裝置狀態本身 (例如重新啟動裝置) 時,這項功能就非常實用。
測試執行程式類型可在 Tradefed 中使用,也可以在執行套件時使用。
如需操作說明,請參閱「在 Trade Federation 中編寫主機導向測試」。
4. 回報測試指標
除了執行結果之外,測試通常也會回報指標。您可以透過多種方法回報指標,具體取決於測試執行程式。
如需範例,請參閱「回報 Tradefed 測試的指標或資料」一文。
5. 自動記錄收集
有些記錄通常用於偵錯問題,例如 Logcat。因此,Tradefed 提供自動化機制,方便收集這些資訊。
如要使用,請參閱「失敗收集的自動記錄」。
6. 自動重試測試
您可以啟用 Tradefed,讓系統自動重試失敗的測試,或在迭代中多次執行某些測試。
詳情請參閱「自動重試測試」。
7. 重試隔離
您可以啟用 Tradefed,嘗試在重試嘗試之間隔離測試執行作業。
詳情請參閱「重試隔離」。
8. 編寫殼層測試
請參閱「在 Trade Federation 中編寫殼層測試」。
請參閱「Trade Federation 中的全域篩選器」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# 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)."]]