自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
GoogleTest
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
平台的 GoogleTest (GTest,有時也稱為「原生測試」) 通常會存取較低層級的 HAL,或針對各種系統服務執行原始 IPC。因此,測試方法通常會與測試的服務緊密結合。
如要整合持續測試基礎架構,請使用 GTest 架構建構 GTest。
範例
以下列舉平台來源中的一些 GTest 範例:
步驟摘要
按照範例 GTest 模組設定操作。
如要自動納入 GTest 依附元件,請在測試模組設定中使用 BUILD_NATIVE_TEST
建構規則。
按照簡單和複雜選項的範例編寫測試設定。
如要使用增量版本建構,請使用 mmm
建構測試模組;如要使用完整版本建構,請使用 mma
:
make hwui_unit_tests -j
使用 Atest 在本機執行測試:
atest hwui_unit_tests
您也可以在 GTest 中加入引數。以下是特別實用的引數:
使用 Trade Federation 測試輔助程式執行測試:
make tradefed-all -j
tradefed.sh run template/local_min --template:map test=hwui_unit_tests
手動安裝及執行:
將產生的測試二進位檔推送至裝置:
adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
/data/nativetest/hwui_unit_tests/hwui_unit_tests
在裝置上叫用測試二進位檔,啟動 GTest 並執行測試:
adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests
如要進一步瞭解如何自訂測試執行作業,請將 --help
參數新增至測試二進位檔。如要進一步瞭解參數,請參閱 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,["# GoogleTest\n\nA GoogleTest (GTest, also sometimes called \"native tests\") for the platform\ntypically accesses lower-level HALs or performs raw IPC against various system\nservices. Because of this, the testing approach is usually tightly coupled with\nthe service under test.\n\nTo integrate with continuous testing infrastructure, build your GTests\nusing the [GTest](https://github.com/google/googletest)\nframework.\n\nExamples\n--------\n\nHere are some examples of GTest in the platform source:\n\n- [frameworks/av/camera/tests](https://android.googlesource.com/platform/frameworks/av/+/android16-release/camera/tests/)\n- [frameworks/native/libs/gui/tests](https://android.googlesource.com/platform/frameworks/native/+/android16-release/libs/gui/tests/)\n\nSummary of steps\n----------------\n\n1. Follow the [example GTest module setup](https://android.googlesource.com/platform/frameworks/base/+/android16-release/libs/hwui/tests/unit/).\n\n2. To automatically include GTest dependencies, use the `BUILD_NATIVE_TEST`\n build rule in your test module configuration.\n\n3. Write a test configuration, following the examples for [simple](/docs/core/tests/development/blueprints)\n and [complex](/docs/core/tests/development/test-config) options.\n\n4. Build the test module with `mmm` for incremental builds, or `mma` for full\n builds:\n\n make hwui_unit_tests -j\n\n5. Run the test locally using [Atest](/docs/core/tests/development/atest):\n\n atest hwui_unit_tests\n\n You can also add arguments to your GTests. The following are especially useful arguments:\n - `native-test-flag` specifies additional flag values to pass to the GTest shell command.\n - `native-test-timeout` specifies a test timeout value in microseconds.\n\n The following example code uses both of these arguments: \n\n atest test-name -- --module-arg test-name:native-test-flag:\"\\\"argument1 argument2\\\"\" \\\n --module-arg test-name:native-test-timeout:60000\n\n6. Run the test with the Trade Federation test harness:\n\n make tradefed-all -j\n tradefed.sh run template/local_min --template:map test=hwui_unit_tests\n\n7. Manually install and run:\n\n 1. Push the generated test binary onto your device:\n\n adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \\\n /data/nativetest/hwui_unit_tests/hwui_unit_tests\n\n 2. Launch GTest and execute the test by invoking the test binary on the device:\n\n adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests\n\n For more information about customizing test execution, add the `--help`\n parameter to your test binary. For more information on parameters, refer to\n the [GTest advanced guide](https://github.com/google/googletest/blob/master/googletest/docs/advanced.md)."]]