Начиная с 27 марта 2025 г. мы рекомендуем использовать android-latest-release
вместо aosp-main
для создания и участия в AOSP. Дополнительные сведения см. в разделе Изменения в AOSP .
GoogleТест
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
GoogleTest (GTest, также иногда называемый «родными тестами») для платформы обычно обращается к низкоуровневым HAL или выполняет сырой IPC против различных системных служб. Из-за этого подход к тестированию обычно тесно связан с тестируемой службой.
Для интеграции с инфраструктурой непрерывного тестирования создавайте свои GTests с использованием фреймворка GTest .
Примеры
Вот несколько примеров GTest в исходном коде платформы:
Краткое изложение шагов
Следуйте примеру настройки модуля GTest .
Чтобы автоматически включить зависимости GTest, используйте правило сборки BUILD_NATIVE_TEST
в конфигурации тестового модуля.
Напишите тестовую конфигурацию, следуя примерам для простых и сложных вариантов.
Соберите тестовый модуль с помощью mmm
для инкрементальных сборок или mma
для полных сборок:
make hwui_unit_tests -j
Запустите тест локально с помощью Atest :
atest hwui_unit_tests
Вы также можете добавлять аргументы в свои GTests. Ниже приведены особенно полезные аргументы:
Запустите тест с помощью тестового инструмента 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-29 UTC.
[[["Прост для понимания","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-29 UTC."],[],[],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)."]]