החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
GoogleTest
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בדרך כלל, בדיקת GoogleTest (GTest, שנקראת לפעמים גם 'בדיקות מקוריות') של הפלטפורמה נגישה ל-HAL ברמה נמוכה יותר או מבצעת IPC גולמי מול שירותי מערכת שונים. לכן, שיטת הבדיקה בדרך כלל משויכת באופן הדוק לשירות שנבדק.
כדי לשלב עם תשתית של בדיקות רציפה, צריך ליצור את בדיקות ה-GTest באמצעות המסגרת GTest.
דוגמאות
ריכזנו כאן כמה דוגמאות ל-GTest במקור הפלטפורמה:
סיכום השלבים
פועלים לפי הדוגמה להגדרת מודול GTest.
כדי לכלול באופן אוטומטי יחסי תלות של GTest, משתמשים בכלל ה-build BUILD_NATIVE_TEST
בתצורה של מודול הבדיקה.
כותבים הגדרת בדיקה לפי הדוגמאות לאפשרויות פשוטות ומורכבות.
יוצרים את מודול הבדיקה באמצעות mmm
לגרסאות build מצטברות, או באמצעות mma
לגרסאות build מלאות:
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
התקנה והפעלה ידנית:
מעבירים את קובץ ה-binary של הבדיקה שנוצר למכשיר:
adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
/data/nativetest/hwui_unit_tests/hwui_unit_tests
מריצים את GTest ומפעילים את הבדיקה על ידי הפעלת קובץ ה-binary של הבדיקה במכשיר:
adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests
מידע נוסף על התאמה אישית של ביצוע הבדיקה זמין במאמר 'הוספת הפרמטר --help
לקובץ הבינארי של הבדיקה'. מידע נוסף על פרמטרים זמין במדריך המתקדם של GTest.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון 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-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)."]]