public final class

AndroidTestOrchestrator

extends Instrumentation
implements TestRunnable.RunFinishedListener
java.lang.Object
   ↳ android.app.Instrumentation
     ↳ android.support.test.orchestrator.AndroidTestOrchestrator

Class Overview

An Instrumentation that executes other instrumentations.

Takes parameters targetPackage and targetInstrumentation, and executes that instrumentation with the same class parameters.

When run normally (i.e. without setting the isolated flag to false) the on device orchestrator will handle test collection and execution. The target instrumentation is executed via shell commands on the device, with one shell command for test collection, followed by one shell command per test.

Each test runs in its own isolated process with its own instrumentation.

Setup

The AndroidTestOrchestrator requires installation of a test services APK android.support.test.services, and the stubapp APK android.support.test.orchestrator.stubapp. The orchestrator is technically instrumenting the stubapp, but it's real purpose is to issue commands to AndroidJUnitRunner or another instrumentation, to run your tests.

Typical usage

Whereas previously you might have called am instrument -w com.example.app/android.support.test.runner.AndroidJUnitRunner you would now execute 'CLASSPATH=$(pm path android.support.test.services) app_process / android.support.test.services.shellexecutor.ShellMain am instrument -w -e targetInstrumentation com.example.app/android.support.test.runner.AndroidJUnitRunner android.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator'

Execution options:

All flags besides the ones listed below are passed by the orchestrator to the target instrumentation.

Pass the -e isolated false flag if you wish the orchestrator to run all your tests in a single process (as if you invoked the target instrumentation directly

Pass -e coverage true -e coverageFilePath /sdcard/foo/ flag to generate coverage files in the given location (The app must have permission to write to the given location). The coverage file naming convention will look like this com.foo.Class#method1.ec. Note, this is only supported when running in isolated mode. Also, it cannot be used together with AndroidJUnitRunner's coverageFile flag. Since the generated coverage files will overwrite each other.

Pass -e clearPackageData flag if you wish the orchestrator to run pm clear context.getPackageName() and pm clear targetContext.getPackageName() commands in between test invocations. Note, the context in the clear command is the App under test context.

Summary

[Expand]
Inherited Constants
From class android.app.Instrumentation
Public Constructors
AndroidTestOrchestrator()
Public Methods
void finish(int resultCode, Bundle results)
void onCreate(Bundle arguments)
boolean onException(Object obj, Throwable e)
void onStart()
void runFinished()
Invoked every time the TestRunnable finishes, including after test collection.
[Expand]
Inherited Methods
From class android.app.Instrumentation
From class java.lang.Object
From interface android.support.test.orchestrator.TestRunnable.RunFinishedListener

Public Constructors

public AndroidTestOrchestrator ()

Public Methods

public void finish (int resultCode, Bundle results)

Parameters
resultCode int
results Bundle

public void onCreate (Bundle arguments)

Parameters
arguments Bundle

public boolean onException (Object obj, Throwable e)

Parameters
obj Object
e Throwable
Returns
boolean

public void onStart ()

public void runFinished ()

Invoked every time the TestRunnable finishes, including after test collection.