Build 1.0_r1(from source)

android.test
Class InstrumentationTestRunner

java.lang.Object
  extended by android.app.Instrumentation
      extended by android.test.InstrumentationTestRunner
All Implemented Interfaces:
TestSuiteProvider

public class InstrumentationTestRunner
extends Instrumentation
implements TestSuiteProvider

An Instrumentation that runs various types of TestCases against an Android package (application). Typical usage:

  1. Write TestCases that perform unit, functional, or performance tests against the classes in your package. Typically these are subclassed from:
  2. In an appropriate AndroidManifest.xml, define the this instrumentation with the appropriate android:targetPackage set.
  3. Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests).
  4. 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.
  5. 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).
  6. Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual TestCase.

Running all tests: adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner

Running unit tests: adb shell am instrument -w -e unit true com.android.foo/android.test.InstrumentationTestRunner

Running instrumentation tests: adb shell am instrument -w -e func true 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

To debug your tests, set a break point in your code and pass: -e debug true
in addition to the other arguments.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.app.Instrumentation
Instrumentation.ActivityMonitor, Instrumentation.ActivityResult
 
Field Summary
static String ARGUMENT_FUNC_CLASS
           
static String ARGUMENT_TEST_CLASS
           
static String ARGUMENT_TEST_PACKAGE
           
static String ARGUMENT_UNIT_CLASS
           
static 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.
static 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.
static 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.
static 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.
static 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.
static String REPORT_VALUE_ID
          This value, if stored with key Instrumentation.REPORT_KEY_IDENTIFIER, identifies InstrumentationTestRunner as the source of the report.
static int REPORT_VALUE_RESULT_ERROR
          The test completed with an error.
static int REPORT_VALUE_RESULT_FAILURE
          The test completed with a failure.
static int REPORT_VALUE_RESULT_OK
          The test completed successfully.
static int REPORT_VALUE_RESULT_START
          The test is starting.
 
Fields inherited from class android.app.Instrumentation
REPORT_KEY_IDENTIFIER, REPORT_KEY_STREAMRESULT
 
Constructor Summary
InstrumentationTestRunner()
           
 
Method Summary
 TestSuite getAllTests()
          Override this to define all of the tests to run in your package.
protected  AndroidTestRunner getAndroidTestRunner()
           
 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.
 
Methods inherited from class android.app.Instrumentation
addMonitor, addMonitor, addMonitor, callActivityOnCreate, callActivityOnDestroy, callActivityOnNewIntent, callActivityOnPause, callActivityOnPostCreate, callActivityOnRestart, callActivityOnRestoreInstanceState, callActivityOnResume, callActivityOnSaveInstanceState, callActivityOnStart, callActivityOnStop, callApplicationOnCreate, checkMonitorHit, endPerformanceSnapshot, execStartActivity, finish, getAllocCounts, getBinderCounts, getComponentName, getContext, getTargetContext, invokeContextMenuAction, invokeMenuActionSync, isProfiling, newActivity, newActivity, newApplication, newApplication, onDestroy, onException, removeMonitor, runOnMainSync, sendCharacterSync, sendKeyDownUpSync, sendKeySync, sendPointerSync, sendStatus, sendStringSync, sendTrackballEventSync, setAutomaticPerformanceSnapshots, setInTouchMode, start, startActivitySync, startAllocCounting, startPerformanceSnapshot, startProfiling, stopAllocCounting, stopProfiling, waitForIdle, waitForIdleSync, waitForMonitor, waitForMonitorWithTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARGUMENT_TEST_CLASS

public static final String ARGUMENT_TEST_CLASS
See Also:
Constant Field Values

ARGUMENT_UNIT_CLASS

public static final String ARGUMENT_UNIT_CLASS
See Also:
Constant Field Values

ARGUMENT_FUNC_CLASS

public static final String ARGUMENT_FUNC_CLASS
See Also:
Constant Field Values

ARGUMENT_TEST_PACKAGE

public static final String ARGUMENT_TEST_PACKAGE
See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

REPORT_VALUE_RESULT_START

public static final int REPORT_VALUE_RESULT_START
The test is starting.

See Also:
Constant Field Values

REPORT_VALUE_RESULT_OK

public static final int REPORT_VALUE_RESULT_OK
The test completed successfully.

See Also:
Constant Field Values

REPORT_VALUE_RESULT_ERROR

public static final int REPORT_VALUE_RESULT_ERROR
The test completed with an error.

See Also:
Constant Field Values

REPORT_VALUE_RESULT_FAILURE

public static final int REPORT_VALUE_RESULT_FAILURE
The test completed with a failure.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values
Constructor Detail

InstrumentationTestRunner

public InstrumentationTestRunner()
Method Detail

onCreate

public void onCreate(Bundle arguments)
Description copied from class: Instrumentation
Called when the instrumentation is starting, before any application code has been loaded. Usually this will be implemented to simply call Instrumentation.start() to begin the instrumentation thread, which will then continue execution in Instrumentation.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(android.content.Intent) to begin the appropriate first activity of the application.

Overrides:
onCreate in class Instrumentation
Parameters:
arguments - Any additional arguments that were supplied when the instrumentation was started.

getAndroidTestRunner

protected AndroidTestRunner getAndroidTestRunner()

onStart

public void onStart()
Description copied from class: Instrumentation
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 Instrumentation.sendKeySync(android.view.KeyEvent) or Instrumentation.startActivitySync(android.content.Intent).

You will typically want to call finish() when this function is done, to end your instrumentation.

Overrides:
onStart in class Instrumentation

getTestSuite

public TestSuite getTestSuite()
Specified by:
getTestSuite in interface TestSuiteProvider

getAllTests

public TestSuite getAllTests()
Override this to define all of the tests to run in your package.


getLoader

public ClassLoader getLoader()
Override this to provide access to the class loader of your package.


Build 1.0_r1(from source)

Please submit a feedback, bug or feature