اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release
بدلاً من aosp-main
لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
اختبارات مضيف JAR
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يجب تنفيذ اختبارات مضيف أرشيف Java (JAR) لتوفير تغطية كاملة لرمز
البرنامج. اتّبِع التعليمات لإنشاء اختبارات الوحدات
المحلية.
اكتب اختبارات وحدات صغيرة للتحقّق من دالة معيّنة فقط.
مثال
يقدّم ملف Blueprint التالي مثالاً بسيطًا لاختبار مضيف JAR لتطبيق Hello World
لنسخه وتعديله وفقًا لاحتياجاتك:
platform_testing/tests/example/jarhosttest/Android.bp
يتوافق ذلك مع رمز الاختبار الفعلي المتوفّر على الرابط التالي:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
في ما يلي لقطة شاشة لملف Blueprint من أجل تسهيل الأمر عليك:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
يشير تعريف java_test_host
في البداية إلى أنّ هذا اختبار مضيف JAR. يمكنك الاطّلاع على مثال لاستخدامه في:
frameworks/base/tools/powermodel/Android.bp
الإعدادات
يمكنك الاطّلاع أدناه على شرح الإعدادات التالية:
يكون إعداد name
مطلوبًا عند تحديد نوع الوحدة java_test_host
(في بداية الكتلة). يمنح هذا الإعداد اسمًا لملف
الوحدة، ويحمل ملف JAR الناتج الاسم نفسه مع إضافة .jar
. في المثال التالي، تم تسمية حزمة JAR الاختبارية الناتجة باسم HelloWorldHostTest.jar
. بالإضافة إلى ذلك، يحدّد هذا الإعداد أيضًا اسم هدف إنشاء لوحدتك، بحيث
يمكنك استخدام make [options] <HelloWorldHostTest>
لإنشاء وحدتك الاختبارية
وجميع الوحدات التابعة لها.
name: "HelloWorldHostTest",
يجعل الإعداد test_suites
الاختبار سهل الاكتشاف من خلال حِزمة اختبار Trade
Federation. يمكن إضافة مجموعات اختبار أخرى هنا، مثل CTS،
لكي تتمكّن من مشاركة اختبار مضيف JAR.
test_suites: ["general-tests"],
يوجّه الإعداد static_libs
نظام الإنشاء إلى دمج محتويات الوحدات المُسمّاة في حزمة APK الناتجة عن الوحدة الحالية.
وهذا يعني أنّه من المتوقّع أن تُنشئ كل وحدة مُسمّاة ملفًا بتنسيق .jar
.
يتم استخدام محتوى الوحدة لتحليل مراجع مسار الطباعة أثناء
وقت الترجمة، ويتم دمجه في حزمة APK الناتجة.
static_libs: [
"junit",
],
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# JAR host tests\n\nJava archive (JAR) host tests should be implemented to provide complete code\ncoverage of your software. Follow the instructions to [Build local unit\ntests](https://developer.android.com/training/testing/unit-testing/local-unit-tests).\nWrite small unit tests to validate a specific function and nothing more.\n\nExample\n-------\n\nThe following Blueprint file provides a simple Hello World JAR host test example\nto copy and adapt to your needs:\n[platform_testing/tests/example/jarhosttest/Android.bp](https://android.googlesource.com/platform/platform_testing/+/android16-release/tests/example/jarhosttest/Android.bp)\n\nThis corresponds to the actual test code found at:\n[platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java](https://android.googlesource.com/platform/platform_testing/+/android16-release/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java)\n\nA snapshot of the Blueprint file is included here for convenience: \n\n java_test_host {\n name: \"HelloWorldHostTest\",\n\n test_suites: [\"general-tests\"],\n\n srcs: [\"test/**/*.java\"],\n\n static_libs: [\n \"junit\",\n \"mockito\",\n ],\n }\n\nThe `java_test_host` declaration at the beginning indicates that this is a JAR\nhost test. See an example of its use in:\n[frameworks/base/tools/powermodel/Android.bp](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/tools/powermodel/Android.bp)\n\nSettings\n--------\n\nSee below for explanations of the following settings:\n\n- The `name` setting is required when the `java_test_host` module type is\n specified (at the start of the block). This setting gives a name to your\n module, and the resulting JAR has the same name and a `.jar` suffix. In the\n example below,the resulting test JAR is named `HelloWorldHostTest.jar`. In\n addition, this setting also defines a make target name for your module, so\n that you can use `make [options] \u003cHelloWorldHostTest\u003e` to build your test\n module and all its dependencies.\n\n name: \"HelloWorldHostTest\",\n\n- The `test_suites` setting makes the test easily discoverable by the Trade\n Federation test harness. Other test suites can be added here, such as CTS,\n so that the JAR host test test can be shared.\n\n test_suites: [\"general-tests\"],\n\n- The `static_libs` setting instructs the build system to incorporate the\n contents of the named modules into the resulting APK of the current module.\n This means that each named module is expected to produce a `.jar` file.\n The module's content is used for resolving classpath references during\n compile time and incorporated into the resulting APK.\n\n static_libs: [\n \"junit\",\n ],"]]