InstrumentationTestRunner
  public
  
  
  
  class
  InstrumentationTestRunner
  
  
  
  
    extends Instrumentation
  
  
  
  
  
      implements
      
        TestSuiteProvider
      
  
  
| java.lang.Object | ||
| ↳ | android.app.Instrumentation | |
| ↳ | android.test.InstrumentationTestRunner | |
      This class was deprecated
      in API level 24.
    Use
 
 AndroidJUnitRunner instead. New tests should be written using the
 Android Testing Support Library.
  
An Instrumentation that runs various types of ERROR(/junit.framework.TestCase)s against
 an Android package (application).
 
Developer Guides
For more information about application testing, read the Testing developer guide.
Typical Usage
- Write ERROR(/junit.framework.TestCase)s 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
 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 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 ERROR(/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/in addition to the other arguments.
Summary
| Constants | |
|---|---|
| String | REPORT_KEY_NAME_CLASSIf included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test class. | 
| String | REPORT_KEY_NAME_TESTIf included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test. | 
| String | REPORT_KEY_NUM_CURRENTIf included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the sequence number of the current test. | 
| String | REPORT_KEY_NUM_TOTALIf included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the total number of tests that are being run. | 
| String | REPORT_KEY_STACKIf included in the status bundle sent to an IInstrumentationWatcher, this key identifies a stack trace describing an error or failure. | 
| String | REPORT_VALUE_IDThis value, if stored with key  | 
| int | REPORT_VALUE_RESULT_ERRORThe test completed with an error. | 
| int | REPORT_VALUE_RESULT_FAILUREThe test completed with a failure. | 
| int | REPORT_VALUE_RESULT_OKThe test completed successfully. | 
| int | REPORT_VALUE_RESULT_STARTThe test is starting. | 
| Inherited constants | 
|---|
| Public constructors | |
|---|---|
| 
      InstrumentationTestRunner()
       | |
| Public methods | |
|---|---|
| 
        
        
        
        
        
        TestSuite | 
      getAllTests()
      Override this to define all of the tests to run in your package. | 
| 
        
        
        
        
        
        Bundle | 
      getArguments()
      Get the arguments passed to this instrumentation. | 
| 
        
        
        
        
        
        ClassLoader | 
      getLoader()
      Override this to provide access to the class loader of your package. | 
| 
        
        
        
        
        
        TestSuite | 
      getTestSuite()
       | 
| 
        
        
        
        
        
        void | 
      onCreate(Bundle arguments)
      Called when the instrumentation is starting, before any application code has been loaded. | 
| 
        
        
        
        
        
        void | 
      onStart()
      Method where the instrumentation thread enters execution. | 
| Protected methods | |
|---|---|
| 
        
        
        
        
        
        void | 
      addTestListener(TestListener listener)
      Add a  | 
| 
        
        
        
        
        
        AndroidTestRunner | 
      getAndroidTestRunner()
       | 
| Inherited methods | |
|---|---|
Constants
REPORT_KEY_NAME_CLASS
public static final String REPORT_KEY_NAME_CLASS
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.
Constant Value: "class"
REPORT_KEY_NAME_TEST
public static final String REPORT_KEY_NAME_TEST
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.
Constant Value: "test"
REPORT_KEY_NUM_CURRENT
public static final String REPORT_KEY_NUM_CURRENT
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.
Constant Value: "current"
REPORT_KEY_NUM_TOTAL
public static final String REPORT_KEY_NUM_TOTAL
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.
Constant Value: "numtests"
REPORT_KEY_STACK
public static final String REPORT_KEY_STACK
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.
Constant Value: "stack"
REPORT_VALUE_ID
public static final String REPORT_VALUE_ID
This value, if stored with key Instrumentation.REPORT_KEY_IDENTIFIER,
 identifies InstrumentationTestRunner as the source of the report.  This is sent with all
 status messages.
Constant Value: "InstrumentationTestRunner"
REPORT_VALUE_RESULT_ERROR
public static final int REPORT_VALUE_RESULT_ERROR
The test completed with an error.
Constant Value: -1 (0xffffffff)
REPORT_VALUE_RESULT_FAILURE
public static final int REPORT_VALUE_RESULT_FAILURE
The test completed with a failure.
Constant Value: -2 (0xfffffffe)
REPORT_VALUE_RESULT_OK
public static final int REPORT_VALUE_RESULT_OK
The test completed successfully.
Constant Value: 0 (0x00000000)
REPORT_VALUE_RESULT_START
public static final int REPORT_VALUE_RESULT_START
The test is starting.
Constant Value: 1 (0x00000001)
Public constructors
InstrumentationTestRunner
public InstrumentationTestRunner ()
Public methods
getAllTests
public TestSuite getAllTests ()
Override this to define all of the tests to run in your package.
| Returns | |
|---|---|
| TestSuite | |
getArguments
public Bundle getArguments ()
Get the arguments passed to this instrumentation.
| Returns | |
|---|---|
| Bundle | the Bundle object | 
getLoader
public ClassLoader getLoader ()
Override this to provide access to the class loader of your package.
| Returns | |
|---|---|
| ClassLoader | |
onCreate
public void onCreate (Bundle arguments)
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 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
public void onStart ()
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(KeyEvent) or startActivitySync(Intent).
 
You will typically want to call finish() when this function is done, to end your instrumentation.
Protected methods
addTestListener
protected void addTestListener (TestListener listener)
Add a ERROR(/TestListener)
| Parameters | |
|---|---|
| listener | TestListener | 
getAndroidTestRunner
protected AndroidTestRunner getAndroidTestRunner ()
| Returns | |
|---|---|
| AndroidTestRunner | |
