Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
GoogleTest
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
GoogleTest (GTest, terkadang juga disebut "pengujian native") untuk platform
biasanya mengakses HAL tingkat rendah atau melakukan IPC mentah terhadap berbagai layanan
sistem. Oleh karena itu, pendekatan pengujian biasanya terikat erat dengan
layanan yang sedang diuji.
Untuk berintegrasi dengan infrastruktur pengujian berkelanjutan, build GTest Anda
menggunakan framework
GTest.
Contoh
Berikut beberapa contoh GTest dalam sumber platform:
Ringkasan langkah
Ikuti contoh penyiapan modul GTest.
Untuk menyertakan dependensi GTest secara otomatis, gunakan aturan build
BUILD_NATIVE_TEST
dalam konfigurasi modul pengujian Anda.
Tulis konfigurasi pengujian, dengan mengikuti contoh untuk opsi sederhana
dan kompleks.
Build modul pengujian dengan mmm
untuk build inkremental, atau mma
untuk build
lengkap:
make hwui_unit_tests -j
Jalankan pengujian secara lokal menggunakan Atest:
atest hwui_unit_tests
Anda juga dapat menambahkan argumen ke GTests. Berikut adalah argumen yang sangat berguna:
Jalankan pengujian dengan harness pengujian Trade Federation:
make tradefed-all -j
tradefed.sh run template/local_min --template:map test=hwui_unit_tests
Menginstal dan menjalankan secara manual:
Kirim biner pengujian yang dihasilkan ke perangkat Anda:
adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
/data/nativetest/hwui_unit_tests/hwui_unit_tests
Luncurkan GTest dan jalankan pengujian dengan memanggil biner pengujian di perangkat:
adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests
Untuk informasi selengkapnya tentang menyesuaikan eksekusi pengujian, tambahkan parameter --help
ke biner pengujian Anda. Untuk informasi selengkapnya tentang parameter, lihat
panduan lanjutan GTest.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 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)."]]