تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
مع توسّع تطبيقك، قد تجد أنّه من المفيد وضع بعض مكوّنات تطبيقك في عملية أخرى غير العملية الرئيسية لتطبيقك. لاختبار مكوّنات التطبيق في هذه العمليات غير التلقائية، يمكنك استخدام وظيفة Multiprocess Espresso.
تتيح لك هذه الأداة، المتوفّرة على الإصدار 8.0 من نظام التشغيل Android (المستوى 26 من واجهة برمجة التطبيقات) والإصدارات الأحدث، اختبار تفاعلات واجهة المستخدم في تطبيقك بسلاسة والتي تتجاوز حدود عملية تطبيقك مع الحفاظ على ضمانات المزامنة في Espresso.
عند استخدام Multiprocess Espresso، يجب مراعاة ما يلي بشأن تحديد الإصدار والنطاق:
يجب أن يستهدف تطبيقك الإصدار 8.0 من نظام التشغيل Android (المستوى 26 لواجهة برمجة التطبيقات) أو الإصدارات الأحدث.
لا يمكن للأداة اختبار مكوّنات التطبيق التي تضمّنها في العمليات ضمن حزمة تطبيقك. ولا يمكنها اختبار العمليات الخارجية.
استخدام الأداة
لاختبار عملية داخل تطبيقك باستخدام Multiprocess Espresso، أضِف مرجعًا إلى العنصر espresso-remote في ملف build.gradle الخاص بتطبيقك:
يشير المقتطف السابق إلى إطار عمل Android بأنّك تريد اختبار كل عملية في حزمة تطبيقك. إذا أردت اختبار مجموعة فرعية فقط من عمليات تطبيقك، يمكنك تحديد قائمة مفصولة بفواصل ضمن العنصر targetProcesses بدلاً من ذلك:
عند اختبار تطبيقك وتشغيل عمليته التلقائية، قد تنفّذ تفاعلاً مع واجهة المستخدم، مثل الضغط على زر، ما يؤدي إلى بدء نشاط في عملية ثانوية. بعد ذلك، يُكمل النظام الخطوات التالية لتفعيل الاختبارات التي تجري على مستوى عمليات متعددة باستخدام Espresso:
ينشئ إطار عمل Android عملية جديدة ويبدأها لتتبُّع البنية التنقّلية لتطبيقك. يتضمّن كل إجراء Instrumentation نسخة جديدة من AndroidJUnitRunner.
في هذه المرحلة، لا يمكن لعمليتَي قياس الأداء التواصل مع بعضهما البعض.
تجري النسختان من
AndroidJUnitRunner
عملية تبادل تأكيد الاتصال لإنشاء اتصال بينهما. في الوقت نفسه، يربط كل مثيل من AndroidJUnitRunner جميع العملاء المسجّلين، مثل Espresso، بنظرائهم في العمليات الأخرى، ما يتيح لهؤلاء العملاء إنشاء قناة اتصال مباشرة بينهم.
يستمر كل AndroidJUnitRunner
مثيل في البحث عن مثيلات أدوات القياس وعملاء إطار عمل الاختبار المضافة حديثًا، وإنشاء قنوات اتصال إضافية حسب الحاجة.
يوضّح الشكل 1 نتيجة هذه العملية:
الشكل 1. إعداد اتصال بين عمليات أدوات متعددة باستخدام Multiprocess Espresso
مراجع إضافية
لمزيد من المعلومات حول هذا الموضوع، يُرجى الاطّلاع على المراجع التالية.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-08 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-08-08 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Multiprocess Espresso\n\nAs your app grows, you might find it useful to place some of your app components\nin a process other than your app's main process. To test app components in these\n*non-default processes*, you can use the functionality of Multiprocess Espresso.\nThis tool, available on Android 8.0 (API level 26) and higher, allows you to\nseamlessly test your app's UI interactions that cross your app's process\nboundaries while maintaining Espresso's synchronization guarantees.\n\nWhen using Multiprocess Espresso, keep the following versioning and scope\nconsiderations in mind:\n\n- Your app must target Android 8.0 (API level 26) or higher.\n- The tool can only test app components that you include in processes within your app's package. It cannot test external processes.\n\nUse the tool\n------------\n\nTo test a process within your app using Multiprocess Espresso, add a reference\nto the **espresso-remote** artifact in your app's `build.gradle` file:\n\napp/build.gradle \n\n### Groovy\n\n```groovy\ndependencies {\n ...\n androidTestImplementation 'androidx.test.espresso:espresso-remote:3.6.1'\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n ...\n androidTestImplementation('androidx.test.espresso:espresso-remote:3.6.1')\n}\n```\n\nYou also need to add the following to your app's `androidTest` manifest:\n\n- An `\u003cinstrumentation\u003e` element that defines the process.\n- A `\u003cmeta-data\u003e` element indicating that you want to use Multiprocess Espresso.\n\nThe following code snippet shows how to add these elements:\n\nsrc/androidTest/AndroidManifest.xml \n\n```xml\n\u003cmanifest ... package=\"androidx.test.mytestapp.tests\"\u003e\n \u003cuses-sdk android:targetSdkVersion=\"27\" android:minSdkVersion=\"14\" /\u003e\n \u003cinstrumentation\n android:name=\"androidx.test.runner.AndroidJUnitRunner\"\n android:targetPackage=\"androidx.test.mytestapp\"\n android:targetProcesses=\"*\"\u003e\n \u003cmeta-data\n android:name=\"remoteMethod\"\n android:value=\"androidx.test.espresso.remote.EspressoRemote#remoteInit\" /\u003e\n \u003c/instrumentation\u003e\n\u003c/manifest\u003e\n```\n\nThe previous snippet indicates to the Android framework that you want it to test\nevery process in your app's package. If you want to test only a subset of your\napp's processes, you can specify a comma-separated list within the\n[targetProcesses](/reference/android/content/pm/InstrumentationInfo#targetProcesses) element instead: \n\n \u003cinstrumentation\n ...\n android:targetProcesses=\n \"androidx.test.mytestapp:myFirstAppProcessToTest,\n androidx.test.mytestapp:mySecondAppProcessToTest\" ... /\u003e\n\n| **Note:** Multiprocess Espresso ignores the value of [targetProcesses](/reference/android/content/pm/InstrumentationInfo#targetProcesses) if you set it to your app package's main process.\n\nUnderstand the tool's architecture\n----------------------------------\n\nWhen you test your app and launch its default process, you might perform a UI\ninteraction, such as a button press, that starts an activity in a secondary\nprocess. The system then completes the following steps to enable cross-process\ntesting using Espresso:\n\n1. The Android Framework creates and starts a new process to follow your app's navigational structure. Each [Instrumentation](/reference/android/app/Instrumentation) process includes a new instance of [`AndroidJUnitRunner`](/reference/androidx/test/runner/AndroidJUnitRunner). At this stage, the 2 instrumentation processes cannot communicate with each other.\n2. Each [`AndroidJUnitRunner`](/reference/androidx/test/runner/AndroidJUnitRunner) instance registers Espresso as its testing framework.\n3. The 2 instances of [`AndroidJUnitRunner`](/reference/androidx/test/runner/AndroidJUnitRunner) perform a handshake to establish a connection between each other. At the same time, each [`AndroidJUnitRunner`](/reference/androidx/test/runner/AndroidJUnitRunner) instance connects all registered clients like Espresso with their respective counterparts in other processes so that these clients can form a direct communication channel between themselves.\n4. Each [`AndroidJUnitRunner`](/reference/androidx/test/runner/AndroidJUnitRunner) instance continues to look for newly-added instrumentation instances and testing framework clients, establishing additional communication channels as needed.\n\nFigure 1 illustrates the result of this process:\n**Figure 1.** Establishing communication between multiple instrumentation processes using Multiprocess Espresso\n\nAdditional resources\n--------------------\n\nFor further information on this topic, consult the following resources.\n\n- [Test-Driven Development on Android with the Android Testing Support\n Library](https://www.youtube.com/watch?v=pK7W5npkhho&start=2201) session video from Google I/O 2017, beginning at 36:41."]]