{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AndroidTestOrchestrator

class AndroidTestOrchestrator : TestRunnable.RunFinishedListener


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 androidx.test.services, and the stubapp APK androidx.test.orchestrator.stubapp. The orchestrator is technically instrumenting the stubapp, but it's real purpose is to issue commands to androidx.test.runner.AndroidJUnitRunner or another instrumentation, to run your tests.

Typical usage

Whereas previously you might have called am instrument -w com.example.app/androidx.test.runner.AndroidJUnitRunner you would now execute 'CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -w -e targetInstrumentation com.example.app/androidx.test.runner.AndroidJUnitRunner androidx.test.orchestrator/androidx.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.

Pass -e orchestratorDebug flag if you need to debug orchestrator itself. Note, to debug test code you still need to pass -e debug.

Summary

Public constructors

Public functions

Unit
finish(resultCode: Int, results: Bundle)
Unit
onCreate(arguments: Bundle)
Boolean
Unit
Unit

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

Public constructors

AndroidTestOrchestrator

AndroidTestOrchestrator()

Public functions

finish

fun finish(resultCode: Int, results: Bundle): Unit

onCreate

fun onCreate(arguments: Bundle): Unit

onException

fun onException(obj: Any, e: Throwable): Boolean

onStart

fun onStart(): Unit

runFinished

fun runFinished(): Unit

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