@Deprecated public class InstrumentationTestRunner extends Instrumentation implements TestSuiteProvider
Instrumentation
that runs various types of junit.framework.TestCase
s against
an Android package (application).
For more information about application testing, read the Testing developer guide.
junit.framework.TestCase
s that perform unit, functional, or performance tests
against the classes in your package. Typically these are subclassed from:
android:targetPackage
attribute 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.
InstrumentationTestCase
.
InstrumentationTestCase
(and are not performance tests).
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/Instrumentation.ActivityMonitor, Instrumentation.ActivityResult, Instrumentation.UiAutomationFlags
Modifier and Type | Field and Description |
---|---|
static String |
ARGUMENT_DELAY_MSEC
Deprecated.
|
static String |
ARGUMENT_TEST_CLASS
Deprecated.
|
static String |
ARGUMENT_TEST_PACKAGE
Deprecated.
|
static String |
ARGUMENT_TEST_SIZE_PREDICATE
Deprecated.
|
static String |
REPORT_KEY_NAME_CLASS
Deprecated.
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
Deprecated.
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
Deprecated.
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
Deprecated.
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
Deprecated.
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
Deprecated.
This value, if stored with key
Instrumentation.REPORT_KEY_IDENTIFIER ,
identifies InstrumentationTestRunner as the source of the report. |
static int |
REPORT_VALUE_RESULT_ERROR
Deprecated.
The test completed with an error.
|
static int |
REPORT_VALUE_RESULT_FAILURE
Deprecated.
The test completed with a failure.
|
static int |
REPORT_VALUE_RESULT_OK
Deprecated.
The test completed successfully.
|
static int |
REPORT_VALUE_RESULT_START
Deprecated.
The test is starting.
|
REPORT_KEY_IDENTIFIER, REPORT_KEY_STREAMRESULT
Constructor and Description |
---|
InstrumentationTestRunner()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addTestListener(TestListener listener)
Deprecated.
Add a
TestListener |
TestSuite |
getAllTests()
Deprecated.
Override this to define all of the tests to run in your package.
|
protected AndroidTestRunner |
getAndroidTestRunner()
Deprecated.
|
Bundle |
getArguments()
Deprecated.
Get the arguments passed to this instrumentation.
|
ClassLoader |
getLoader()
Deprecated.
Override this to provide access to the class loader of your package.
|
TestSuite |
getTestSuite()
Deprecated.
|
void |
onCreate(Bundle arguments)
Deprecated.
Called when the instrumentation is starting, before any application code
has been loaded.
|
void |
onStart()
Deprecated.
Method where the instrumentation thread enters execution.
|
addMonitor, addMonitor, addMonitor, callActivityOnCreate, callActivityOnCreate, callActivityOnDestroy, callActivityOnNewIntent, callActivityOnNewIntent, callActivityOnPause, callActivityOnPostCreate, callActivityOnPostCreate, callActivityOnRestart, callActivityOnRestoreInstanceState, callActivityOnRestoreInstanceState, callActivityOnResume, callActivityOnSaveInstanceState, callActivityOnSaveInstanceState, callActivityOnStart, callActivityOnStop, callActivityOnUserLeaving, callApplicationOnCreate, checkMonitorHit, checkStartActivityResult, endPerformanceSnapshot, execStartActivities, execStartActivitiesAsUser, execStartActivity, execStartActivity, execStartActivity, execStartActivityAsCaller, execStartActivityFromAppTask, finish, getAllocCounts, getBinderCounts, getComponentName, getContext, getTargetContext, getUiAutomation, getUiAutomation, 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
public static final String ARGUMENT_TEST_CLASS
public static final String ARGUMENT_TEST_PACKAGE
public static final String ARGUMENT_TEST_SIZE_PREDICATE
public static final String ARGUMENT_DELAY_MSEC
public static final String REPORT_VALUE_ID
Instrumentation.REPORT_KEY_IDENTIFIER
,
identifies InstrumentationTestRunner as the source of the report. This is sent with all
status messages.public static final String REPORT_KEY_NUM_TOTAL
public static final String REPORT_KEY_NUM_CURRENT
public static final String REPORT_KEY_NAME_CLASS
public static final String REPORT_KEY_NAME_TEST
public static final int REPORT_VALUE_RESULT_START
public static final int REPORT_VALUE_RESULT_OK
public static final int REPORT_VALUE_RESULT_ERROR
public static final int REPORT_VALUE_RESULT_FAILURE
public static final String REPORT_KEY_STACK
public void onCreate(Bundle arguments)
Instrumentation
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.
onCreate
in class Instrumentation
arguments
- Any additional arguments that were supplied when the
instrumentation was started.public Bundle getArguments()
protected void addTestListener(TestListener listener)
TestListener
protected AndroidTestRunner getAndroidTestRunner()
public void onStart()
Instrumentation
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.
onStart
in class Instrumentation
public TestSuite getTestSuite()
getTestSuite
in interface TestSuiteProvider
public TestSuite getAllTests()
public ClassLoader getLoader()