اختبار رمز المنصّة باستخدام atest
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يتكامل Android Studio for Platform (ASfP) مع أداة سطر الأوامر atest
، ما يتيح لك إجراء اختبارات على جهازك المتصل أو المحاكي مباشرةً من بيئة التطوير المتكاملة.
المتطلّبات الأساسية
- افتح مشروع ASfP باستخدام رمز مصدر AOSP.
- إنشاء الرمز البرمجي ونقله إلى جهاز أو محاكي بنجاح
- ابدأ إعداد بيئة الإنشاء باستخدام
source build/envsetup.sh
وlunch
.
إجراء الاختبارات
يمكنك إجراء الاختبارات باستخدام atest
في "برنامج ASfP" بعدة طرق:
رموز التشغيل في الهامش: انقر على رمز التشغيل play_circle
بجانب فئة اختبار أو طريقة اختبار في المحرّر لتشغيل هذا الاختبار المحدّد.
قائمة النقر بزر الماوس الأيمن: انقر بزر الماوس الأيمن على ملف اختبار أو فئة أو طريقة في نافذة
Project أو المحرِّر، ثم اختَر Run 'atest'.
استخدام الوحدة الطرفية: افتح الوحدة الطرفية المدمجة في ASfP (عرض > نوافذ الأدوات > الوحدة الطرفية) ونفِّذ أوامر atest
مباشرةً. على سبيل المثال: bash
atest MyTestModule
atest MyTestClass#myTestMethod
عرض نتائج الاختبار
يتم عرض نتائج الاختبار في نافذة أداة التشغيل ضمن ASfP. تعرض هذه النافذة مدى تقدّم الاختبار وحالة النجاح أو الفشل، كما توفّر السجلات والنتائج لكل اختبار.
إعدادات الاختبار
عند إجراء اختبار من الهامش أو قائمة النقر بزر الماوس الأيمن، تنشئ ASfP تلقائيًا إعدادًا مؤقتًا للتنفيذ أو تصحيح الأخطاء. يمكنك تعديل هذه الإعدادات وحفظها لإعادة تنفيذ الاختبارات بسرعة باستخدام خيارات أو علامات معيّنة:
- انتقِل إلى تشغيل > تعديل الإعدادات.
- ابحث عن إعداد
atest
الذي تريد تعديله أو أنشئ إعدادًا جديدًا من خلال النقر على الزر + واختيار الأحدث.
- حدِّد وحدة الاختبار والفئة والطريقة، وأضِف أي
atest
خيارات سطر أوامرatest
ضرورية.
نصائح حول الاختبار
- الاختبارات المستهدَفة: يمكنك إجراء الاختبارات المحدّدة التي تحتاج إليها فقط لتوفير الوقت. استخدِم التنسيق
Module:Class#Method
أو فلاتر atest
أخرى.
- استخدام لقطات المحاكي: لإجراء الاختبارات بشكل أسرع على المحاكيات، ننصحك
باستخدام اللقطات للرجوع بسرعة إلى حالة جيدة معروفة.
- التحقّق من السجلات: استخدِم السجلات في نافذة أداة التشغيل لتشخيص أي أخطاء في الاختبار.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-09-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-09-05 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["Android Studio for Platform (ASfP) integrates with the `atest` command-line\ntool, letting you run tests on your connected device or emulator directly from\nthe IDE.\n\nPrerequisites\n\n- Open an ASfP project with your AOSP source code.\n- Successfully build and flash your code to a device or emulator.\n- Initialize your build environment using `source build/envsetup.sh` and `lunch`.\n\nRun tests\n\nYou can run tests using `atest` in ASfP in several ways:\n\n- **Gutter run icons:** Click the **Run** icon play_circle\n\n next to a test class or method in the editor to run that specific test.\n- **Right-click menu:** Right-click on a test file, class, or method in the\n Project window or editor and select **Run 'atest'**.\n\n- **Using the terminal:** Open the integrated terminal in ASfP (**View \\\u003e Tool\n Windows \\\u003e Terminal** ) and run `atest` commands directly. For example: `bash\n atest MyTestModule\n atest MyTestClass#myTestMethod`\n\nView test results\n\nTest results are displayed in the **Run** tool window within ASfP. This window\nshows the test progress, pass or fail status, and provides logs and output for\neach test.\n\nTest configurations\n\nWhen you run a test from the gutter or right-click menu, ASfP automatically\ncreates a temporary run or debug configuration. You can modify and save these\nconfigurations to quickly re-run tests with specific options or flags:\n\n1. Go to **Run \\\u003e Edit Configurations**.\n2. Find the `atest` configuration you want to modify or create a new one by clicking the **+** button and selecting **atest**.\n3. Specify the test module, class, method, and add any necessary `atest` command-line options.\n\nTips for testing\n\n- **Targeted testing:** Run only the specific tests you need to save time. Use the format `Module:Class#Method` or other `atest` filters.\n- **Use emulator snapshots:** For faster test runs on emulators, consider using snapshots to quickly revert to a known good state.\n- **Check logs:** Use the logs in the **Run** tool window to diagnose any test failures."]]