自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Android 平台測試
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 開放原始碼計畫 (AOSP) 提供多種工具和測試套件,可用於測試實作項目的各個部分。使用本節的頁面前,請先熟悉下列術語:
- Android 相容裝置
- 可執行任何由第三方開發人員使用 Android SDK 和 NDK 編寫的第三方應用程式的裝置。與 Android 相容的裝置必須遵守相容性定義說明文件 (CDD) 的規定,並通過相容性測試套件 (CTS) 測試。支援 Android 的裝置可參與 Android 生態系統,包括 Google Play 的潛在授權、Google 行動服務 (GMS) 應用程式和 API 套件的潛在授權,以及 Android 商標的使用權。任何人都可以使用 Android 原始碼,但裝置必須與 Android 相容,才能算是 Android 生態系統的一部分。
- 成果
- 可在本機排解問題的建構相關記錄。
- 相容性定義文件 (CDD)
- 這份文件列出 Android 相容裝置的軟硬體需求。
- Compatibility Test Suite (CTS)
免費的商業級測試套件,可下載為 AOSP 中的二進位檔或來源。CTS 是一組單元測試,可整合至您的日常工作流程。CTS 的目的在於找出不相容性問題,並確保軟體在整個開發過程中保持相容性。
CTS 和平台測試並非互斥。以下列出一些一般準則:
- 如果測試是驗證架構 API 函式或行為的正確性,且應在所有原始設備製造商 (OEM) 合作夥伴中強制執行,則應在 CTS 中進行測試。
- 如果測試目的是在平台開發期間找出回歸現象,且可能需要特殊權限才能執行,並可能依實作細節 (如 AOSP 中發布的內容) 而定,那麼應視為平台測試。
- Google 行動服務 (GMS)
可在裝置上預先安裝的 Google 應用程式和 API 集合。
- GoogleTest (GTest)
C++ 測試和模擬架構。GTest 二進位檔通常會存取較低層級的抽象層,或針對各種系統服務執行原始 IPC。GTest 的測試方法通常會與要測試的服務緊密結合。CTS 包含 GTest 架構。
- 檢測設備測試
由 am instrument
指令啟動的特殊測試執行環境,其中會重新啟動目標應用程式程序,並使用基本應用程式內容進行初始化,並在應用程式程序虛擬機器中啟動檢測執行緒。CTS 包含檢測設備測試。
- Logcat
這是一種指令列工具,可建立系統訊息記錄,包括裝置擲回錯誤時的堆疊追蹤,以及您使用 Log
類別在應用程式寫入的訊息。
- 記錄
使用記錄追蹤電腦系統事件 (例如錯誤)。由於 Logcat 工具會結合多種標準,因此在 Android 中記錄資料相當複雜。
- postsubmit test
當新的修補程式提交至通用核心分支時,系統會執行的 Android 測試。輸入 aosp_kernel
做為部分分支名稱,即可查看可用結果的核心分支清單。舉例來說,您可以前往 https://ci.android.com/builds/branches/aosp_kernel-common-android-mainline/grid 查看 android-mainline
的結果。
- presubmit test
這項測試可避免將失敗情形引入常見的核心。
- Trade Federation
也稱為 Tradefed,這是專為在 Android 裝置上執行測試而設計的持續測試架構。舉例來說,Tradefed 可用於執行 Compatibility Test Suite 和供應商 Test Suite 測試。
- 供應商測試套件 (VTS)
一組 Android 測試的廣泛功能,可促進以測試為導向的開發程序,並自動執行硬體抽象層 (HAL) 和 OS 核心測試。
平台測試類型
平台測試通常會與一或多個 Android 系統服務或 HAL 層互動,測試測試對象的功能,並斷言測試結果是否正確。平台測試可能會:
- (類型 1) 使用 Android 架構的練習架構 API。執行的特定 API 可能包括:
- 專供第三方應用程式使用的公用 API
- 隱藏的 API,專供特權應用程式使用,也就是系統 API 或私人 API (
@hide
或 protected
、package private
)
- (類型 2) 直接使用原始 Binder 或 IPC 代理程式叫用 Android 系統服務。
- (類型 3) 使用低階 API 或 IPC 介面,直接與 HAL 互動。
類型 1 和 2 的測試通常是檢測設備測試,而類型 3 的測試通常是 GTest。
後續步驟
以下是您可以參考的文件清單,其中包含更多詳細資訊:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Android platform testing\n\nAndroid Open Source Project (AOSP) provides several tools and test suites\nfor testing various parts of your implementation. Before using the pages in this\nsection, you should be familiar with the following terms:\n\n*Android-compatible device*\n: A device that can run any third-party app written by third-party developers\n using the Android SDK and NDK. Android-compatible devices must adhere to the\n requirements of the\n [Compatibility Definition Document (CDD)](#CDD) and pass the\n [Compatibility Test Suite (CTS)](#cts). Android-compatible\n devices are eligible to participate in the Android ecosystem, which includes\n potential licensure of Google Play, potential licensure of the\n [Google Mobile Services (GMS)](#gms) suite of\n app and APIs, and use of the Android trademark. Anyone is welcome to\n use the Android source code, but to be considered part of the Android ecosystem,\n a device must be Android compatible.\n\n*artifact*\n: A build-related log that enables local troubleshooting.\n\n*Compatibility Definition Document (CDD)*\n: A document that enumerates the software and hardware requirements for an\n Android-compatible device.\n\n*Compatibility Test Suite (CTS)*\n\n: A free, commercial-grade test suite, available for download as a binary or as\n source in AOSP. The CTS is a set of unit tests designed to be integrated into\n your daily workflow. The intent of CTS is to reveal incompatibilities, and\n ensure that the software remains compatible throughout the development process.\n\n CTS and platform tests aren't mutually exclusive. Here are some general\n guidelines:\n\n - If a test is asserting correctness of framework API functions or behaviors, and the test should be enforced across OEM partners, it should be in CTS.\n - If a test is intended to catch regressions during platform development, and might require privileged permission to carry out, and might be dependent on implementation details (as released in AOSP), it should be a platform test.\n\n*Google Mobile Services (GMS)*\n\n: A collection of Google apps and APIs that can be preinstalled on devices.\n\n*GoogleTest (GTest)*\n\n: A C++ testing and mocking framework. GTest binaries typically\n access lower-level abstraction layers or perform raw IPC against various system\n services. The testing approach for GTest is usually tightly coupled with the\n service being tested. CTS contains the GTest framework.\n\n*instrumentation test*\n\n: A special test execution environment\n launched by the `am instrument` command, where the targeted app process\n is restarted and initialized with basic app context, and an\n instrumentation thread is started inside the app process virtual\n machine. CTS contains instrumentation tests.\n\n*Logcat*\n\n: A command-line tool that creates a log of system messages, including\n stack traces of when the device throws an error and messages that you have\n written from your app with the `Log` class.\n\n*logging*\n\n: Using a log to keep track of computer system events, such\n as errors. Logging in Android is complex due to the mix of standards used that\n are combined in the Logcat tool.\n\n*postsubmit test*\n\n: An Android test that is performed when a new patch is committed to a\n common kernel branch. By entering `aosp_kernel` as a partial branch name, you\n can see a list of kernel branches with results available. For example, results\n for `android-mainline` can be found at\n \u003chttps://ci.android.com/builds/branches/aosp_kernel-common-android-mainline/grid\u003e.\n\n*presubmit test*\n\n: A test used to prevent failures from being introduced into the\n common kernels.\n\n*Trade Federation*\n\n: Also called Tradefed, a continuous test\n framework designed for running tests on Android devices. For example,\n Tradefed is used to run Compatibility Test Suite and Vendor Test Suite tests.\n\n*Vendor Test Suite (VTS)*\n\n: A set of extensive capabilities for\n Android testing, promoting a test-driven development process, and automating\n hardware abstraction layer (HAL) and OS kernel testing.\n\nPlatform test types\n-------------------\n\nA platform test typically interacts with one or more of the Android system\nservices or HAL layers, exercises the\nfunctionalities of the subject under test, and asserts correctness of the\ntesting outcome. A platform test might:\n\n- (Type 1) Exercise framework APIs using Android framework. Specific APIs being exercised can include:\n - Public APIs intended for third-party apps\n - Hidden APIs intended for privileged apps, namely system APIs or private APIs (`@hide`, or `protected`, `package private`)\n- (Type 2) Invoke Android system services using raw binder or IPC proxies directly.\n- (Type 3) Interact directly with HALs using low-level APIs or IPC interfaces.\n\nType 1 and 2 tests are typically instrumentation tests, while type 3 tests are\nusually GTests.\n\nWhat's next?\n------------\n\nHere is a list of documents that you can read for more detailed information:\n\n- If you haven't studied Android architecture, see\n [Architecture overview](/docs/core/architecture).\n\n- If you're creating an Android-compatible device, see\n the [Android compatibility program overview](/docs/compatibility/overview).\n\n- To integrate instrumentation, functional, metric, and JAR host tests\n into a platform continuous testing service, see\n [Test development workflow](/docs/core/tests/development).\n\n- To detect and harden your devices against vulnerabilities,\n see [Security testing](/docs/security/test/fuzz-sanitize).\n\n- To learn about testing your HAL and kernel implementations, see\n [Vendor Test Suite (VTS) and infrastructure](/docs/core/tests/vts).\n\n- For app testing, read\n [Fundamentals of testing Android\n apps](https://developer.android.com/training/testing/fundamentals)\n and conduct the [Advanced Android in Kotlin 05.1:Testing\n Basics](https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-basics/index.html)\n using the\n [samples](https://github.com/android/testing-samples) provided.\n\n- Learn about the basic presubmit testing available to you through repo hooks.\n These hooks can be used to run linters, check formatting, and trigger unit\n tests before proceeding, such as uploading a commit. These hooks are disabled\n by default. For further information, see [AOSP Preupload\n Hooks](https://android.googlesource.com/platform/tools/repohooks/+/refs/heads/android16-release/README.md).\n\n- To read more about logging, see [Understand logging](/docs/core/tests/debug/understanding-logging).\n\n- To understand how to debug Android code, see\n [Debug native Android platform code](/docs/core/tests/debug)."]]