自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
GoogleTest
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
平台的 GoogleTest(GTest,有时也称为“原生测试”)通常会访问较低级别的 HAL,或针对各种系统服务执行原始 IPC。因此,测试方法通常与接受测试的服务密切相关。
如需与持续测试基础架构集成,请使用 GTest 框架构建 GTest。
示例
以下是平台源代码中 GTest 的一些示例:
步骤总结
按照 GTest 模块设置示例操作。
如需自动包含 GTest 依赖项,请在测试模块配置中使用 BUILD_NATIVE_TEST
build 规则。
按照简单和复杂选项的示例编写测试配置。
对于增量 build,请使用 mmm
构建测试模块;对于完整 build,请使用 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-03-26。"],[],[],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)."]]