InstrumentationTestRunner
open classInstrumentationTestRunner: Instrumentation, TestSuiteProvider
| kotlin.Any | ||
| ↳ | android.app.Instrumentation | |
| ↳ | android.test.InstrumentationTestRunner | |
An Instrumentation that runs various types of junit.framework.TestCases against an Android package (application).
Typical Usage
- Write junit.framework.TestCases that perform unit, functional, or performance tests against the classes in your package. Typically these are subclassed from:
- Set the
android:targetPackageattribute of the<instrumentation>element in the test package's manifest. You should set the attribute value to the package name of the target application under test. - Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests).
- Run the instrumentation using "adb shell am instrument -w", with the argument '-e func true' to run all functional tests. These are tests that derive from
android.test.InstrumentationTestCase. - Run the instrumentation using "adb shell am instrument -w", with the argument '-e unit true' to run all unit tests. These are tests that do notderive from
android.test.InstrumentationTestCase(and are not performance tests). - Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual junit.framework.TestCase.
LargeTest and "com.android.foo.MyAnnotation" annotations.
Filter test run to tests without given annotation: adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner
Running a single testcase: adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/android.test.InstrumentationTestRunner
Running a single test: adb shell am instrument -w -e class com.android.foo.FooTest#testFoo com.android.foo/android.test.InstrumentationTestRunner
Running multiple tests: adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner
Running all tests in a java package: adb shell am instrument -w -e package com.android.foo.subpkg com.android.foo/android.test.InstrumentationTestRunner
Including performance tests: adb shell am instrument -w -e perf true com.android.foo/android.test.InstrumentationTestRunner
To debug your tests, set a break point in your code and pass: -e debug true
To run in 'log only' mode -e log true This option will load and iterate through all test classes and methods, but will bypass actual test execution. Useful for quickly obtaining info on the tests to be executed by an instrumentation command.
To generate EMMA code coverage: -e coverage true Note: this requires an emma instrumented build. By default, the code coverage results file will be saved in a /data//coverage.ec file, unless overridden by coverageFile flag (see below)
To specify EMMA code coverage results file path: -e coverageFile /sdcard/myFile.ec in addition to the other arguments.
Summary
| Constants | |
|---|---|
| static String |
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test class. |
| static String |
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test. |
| static String |
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the sequence number of the current test. |
| static String |
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the total number of tests that are being run. |
| static String |
If included in the status bundle sent to an IInstrumentationWatcher, this key identifies a stack trace describing an error or failure. |
| static String |
This value, if stored with key |
| static Int |
The test completed with an error. |
| static Int |
The test completed with a failure. |
| static Int |
The test completed successfully. |
| static Int |
The test is starting. |
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
| Public methods | |
|---|---|
| open TestSuite! |
Override this to define all of the tests to run in your package. |
| open Bundle! |
Get the arguments passed to this instrumentation. |
| open ClassLoader! |
Override this to provide access to the class loader of your package. |
| open TestSuite! | |
| open Unit |
Called when the instrumentation is starting, before any application code has been loaded. |
| open Unit |
onStart()Method where the instrumentation thread enters execution. |
| Protected methods | |
|---|---|
| open Unit |
addTestListener(listener: TestListener!)Add a TestListener |
| open AndroidTestRunner! | |
| Inherited functions | |
|---|---|
Constants
REPORT_KEY_NAME_CLASS
static valREPORT_KEY_NAME_CLASS: String
Deprecated: Deprecated in Java.
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test class. This is sent with any status message describing a specific test being started or completed.
Value: "class"REPORT_KEY_NAME_TEST
static valREPORT_KEY_NAME_TEST: String
Deprecated: Deprecated in Java.
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test. This is sent with any status message describing a specific test being started or completed.
Value: "test"REPORT_KEY_NUM_CURRENT
static valREPORT_KEY_NUM_CURRENT: String
Deprecated: Deprecated in Java.
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the sequence number of the current test. This is sent with any status message describing a specific test being started or completed.
Value: "current"REPORT_KEY_NUM_TOTAL
static valREPORT_KEY_NUM_TOTAL: String
Deprecated: Deprecated in Java.
If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the total number of tests that are being run. This is sent with all status messages.
Value: "numtests"REPORT_KEY_STACK
static valREPORT_KEY_STACK: String
Deprecated: Deprecated in Java.
If included in the status bundle sent to an IInstrumentationWatcher, this key identifies a stack trace describing an error or failure. This is sent with any status message describing a specific test being completed.
Value: "stack"REPORT_VALUE_ID
static valREPORT_VALUE_ID: String
Deprecated: Deprecated in Java.
This value, if stored with key android.app.Instrumentation#REPORT_KEY_IDENTIFIER, identifies InstrumentationTestRunner as the source of the report. This is sent with all status messages.
Value: "InstrumentationTestRunner"REPORT_VALUE_RESULT_ERROR
static valREPORT_VALUE_RESULT_ERROR: Int
Deprecated: Deprecated in Java.
The test completed with an error.
Value: -1REPORT_VALUE_RESULT_FAILURE
static valREPORT_VALUE_RESULT_FAILURE: Int
Deprecated: Deprecated in Java.
The test completed with a failure.
Value: -2REPORT_VALUE_RESULT_OK
static valREPORT_VALUE_RESULT_OK: Int
Deprecated: Deprecated in Java.
The test completed successfully.
Value: 0REPORT_VALUE_RESULT_START
static valREPORT_VALUE_RESULT_START: Int
Deprecated: Deprecated in Java.
The test is starting.
Value: 1Public constructors
InstrumentationTestRunner
InstrumentationTestRunner()
Public methods
getAllTests
open fungetAllTests(): TestSuite!
Deprecated: Deprecated in Java.
Override this to define all of the tests to run in your package.
getArguments
open fungetArguments(): Bundle!
Deprecated: Deprecated in Java.
Get the arguments passed to this instrumentation.
| Return | |
|---|---|
Bundle! |
the Bundle object |
getLoader
open fungetLoader(): ClassLoader!
Deprecated: Deprecated in Java.
Override this to provide access to the class loader of your package.
getTestSuite
open fungetTestSuite(): TestSuite!
Deprecated: Deprecated in Java.
onCreate
open funonCreate(arguments: Bundle!): Unit
Deprecated: Deprecated in Java.
Called when the instrumentation is starting, before any application code has been loaded. Usually this will be implemented to simply call start to begin the instrumentation thread, which will then continue execution in onStart.
If you do not need your own thread -- that is you are writing your instrumentation to be completely asynchronous (returning to the event loop so that the application can run), you can simply begin your instrumentation here, for example call android.content.Context#startActivity to begin the appropriate first activity of the application.
| Parameters | |
|---|---|
arguments |
Bundle!: Any additional arguments that were supplied when the instrumentation was started. |
onStart
open funonStart(): Unit
Deprecated: Deprecated in Java.
Method where the instrumentation thread enters execution. This allows you to run your instrumentation code in a separate thread than the application, so that it can perform blocking operation such as sendKeySync or #startActivitySync.
You will typically want to call finish() when this function is done, to end your instrumentation.
Protected methods
addTestListener
protected open funaddTestListener(listener: TestListener!): Unit
Deprecated: Deprecated in Java.
Add a TestListener
getAndroidTestRunner
protected open fungetAndroidTestRunner(): AndroidTestRunner!
Deprecated: Deprecated in Java.