自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
測試開發工作流程
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要將測試整合至平台持續測試服務,則必須符合本頁指南並遵循建議的流程。
- 使用 Soong 建構系統進行簡易測試設定。
- 採用測試對應功能,直接在 Android 來源樹狀結構中建立提交前後的測試規則。
- 使用 Atest 在本機執行測試。
測試類型
支援的測試類型如下:
功能測試會對測試案例做出通過或失敗的斷言,而指標測試通常會重複執行動作,以便收集時間指標。
有了標準化的輸入/輸出格式,您就不需要為每項測試進行自訂結果剖析和後續處理,而且通用測試輔助程式可用於符合慣例的所有測試。如要瞭解 Android 內含的持續測試架構,請參閱「Trade Federation 總覽」。
測試案例指南
透過持續測試服務執行的測試案例應為密封的,也就是說,所有依附元件都會在測試中宣告並提供。如要瞭解這項原則,請參閱 Google 測試網誌上的「Hermetic Servers」。簡而言之,密封測試不需要:
- Google 帳戶登入
- 已設定連線功能 (通訊/Wi-Fi/藍牙/NFC)
- 傳入的測試參數
- 測試輔助程式針對特定測試案例執行的設定或拆解作業
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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 development workflow\n\nTo integrate tests into a platform continuous testing service, they should meet\nthe guidelines on this page and follow this recommended flow.\n\n1. Use the [Soong build system](https://android.googlesource.com/platform/build/soong/) for [Simple Test Configuration](/docs/core/tests/development/blueprints).\n2. Employ [Test Mapping](/docs/core/tests/development/test-mapping) to create pre- and post-submit test rules directly in the Android source tree.\n3. Run tests locally using [Atest](/docs/core/tests/development/atest).\n\nTest types\n----------\n\nSupported test types are:\n\n- [Instrumentation tests](/docs/core/tests/development/instrumentation) support both functional and metrics tests. See [Test your app](https://developer.android.com/studio/test/) for general app testing guidance.\n- [GoogleTest](/docs/core/tests/development/gtest) (GTest) supports the following test types:\n - [Functional GTests](/docs/core/tests/development/gtest-func-e2e) using the [GTest](https://github.com/google/googletest) framework\n - [Metric tests](/docs/core/tests/development/metrics) using [`google-benchmark`](https://github.com/google/benchmark)\n- [JAR host tests](/docs/core/tests/development/jar) using JUnit\n\nFunctional tests make assertions of pass or fail on test cases, while metrics\ntests generally perform an action repeatedly to collect timing metrics.\n\nWith standardized input/output format, the need for customized result parsing\nand post-processing per test is eliminated, and generic test harnesses can be\nused for all tests that fit into the convention. See the [Trade Federation\nOverview](/docs/core/tests/tradefed) for the continuous test framework\nincluded with Android.\n\nTest case guidelines\n--------------------\n\nTest cases executed through the continuous testing service are expected to be\n**hermetic** , meaning that all dependencies are declared and provided with the\ntests. See [Hermetic Servers on the Google Testing\nBlog](https://testing.googleblog.com/2012/10/hermetic-servers.html)\nfor an understanding of this principle. In short, hermetic tests require **no**:\n\n- Google Account sign-in\n- Connectivity configured (telephony/Wi-Fi/Bluetooth/NFC)\n- Test parameters passed in\n- Setup or tear down performed by test harness for a specific test case"]]