콘텐츠로 건너뛰기

자주 방문한 페이지

최근 방문한 페이지

navigation

Multiprocess Espresso

As your app grows, you might find it useful to place some of your app components in a process other than your app's main process. To test app components in these non-default processes, you can use the functionality of Multiprocess Espresso. This tool, available on Android 8.0 (API level 26) and higher, allows you to seamlessly test your app's UI interactions that cross your app's process boundaries while maintaining Espresso's synchronization guarantees.

When using Multiprocess Espresso, keep the following versioning and scope considerations in mind:

Using the tool

To test a process within your app using Multiprocess Espresso, add the following to your app's androidTest manifest:

The following code snippet shows how to add these elements:

src/androidTest/AndroidManifest.xml

<manifest ... package="android.support.test.mytestapp.tests">
  <uses-sdk android:targetSdkVersion="26" android:minSdkVersion="10" />
  <instrumentation
    android:name="android.support.test.runner.AndroidJUnitRunner"
    android:targetPackage="android.support.mytestapp"
    android:targetProcesses="*" />
  <meta-data
    android:name="remoteMethod"
    android:value="android.support.test.espresso.remote.EspressoRemote#remoteInit" />
</manifest>

The previous snippet indicates to the Android framework that you want it to test every process in your app's package. If you want to test only a subset of your app's processes, you can specify a comma-separated list within the targetProcesses element instead:

<instrumentation
    ...
    android:targetProcesses=
            "android.support.test.mytestapp:myFirstAppProcessToTest,
             android.support.test.mytestapp:mySecondAppProcessToTest" ... />

Understanding the tool's architecture

When you test your app and launch its default process, you might perform a UI interaction, such as a button press, that starts an activity in a secondary process. The system then completes the following steps to enable cross-process testing using Espresso:

  1. The Android Framework creates and starts a new process to follow your app's navigational structure. Each Instrumentation process includes a new instance of AndroidJUnitRunner. At this stage, the 2 instrumentation processes cannot communicate with each other.
  2. Each AndroidJUnitRunner instance registers Espresso as its testing framework.
  3. The 2 instances of AndroidJUnitRunner perform a handshake to establish a connection between each other. At the same time, each 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.
  4. Each AndroidJUnitRunner instance continues to look for newly-added instrumentation instances and testing framework clients, establishing additional communication channels as needed.

Figure 1 illustrates the result of this process:

Figure 1. Establishing communication between multiple instrumentation processes using Multiprocess Espresso

The Test-Driven Development on Android with the Android Testing Support Library session video from Google I/O 2017, beginning at 36:41, also explains this process.

이 사이트는 쿠키를 사용하여 사이트별 언어 및 표시 옵션에 대한 환경설정을 저장합니다.

Google Play에서 성공을 거두는 데 도움이 되는 최신 Android 개발자 뉴스 및 도움말을 받아 보세요.

* 필수 입력란

완료되었습니다.

WeChat에서 Google Developers 팔로우하기

이 사이트를 (으)로 탐색할까요?

페이지를 요청했지만 이 사이트의 언어 환경설정은 입니다.

언어 환경설정을 변경하고 이 사이트를 (으)로 탐색할까요? 언어 환경설정을 나중에 변경하려면 각 페이지 하단의 언어 메뉴를 사용하세요.

이 클래스를 사용하려면 API 수준 이상이 필요합니다.

문서에 대해 선택한 API 수준이 이므로 이 문서가 표시되지 않습니다. 왼쪽 탐색 메뉴의 선택기로 문서 API 수준을 변경할 수 있습니다.

앱에 필요한 API 수준 지정에 관한 자세한 내용은 다양한 플랫폼 버전 지원을 참조하세요.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)