public class InstrumentationTestCase extends
Instrumentation
.Constructor and Description |
---|
InstrumentationTestCase() |
Modifier and Type | Method and Description |
---|---|
Instrumentation |
getInstrumentation()
Inheritors can access the instrumentation using this.
|
void |
injectInsrumentation(Instrumentation instrumentation)
Deprecated.
Incorrect spelling,
use
injectInstrumentation(android.app.Instrumentation) instead. |
void |
injectInstrumentation(Instrumentation instrumentation)
Injects instrumentation into this test case.
|
<T extends Activity> |
launchActivity(String pkg,
Class<T> activityCls,
Bundle extras)
Utility method for launching an activity.
|
<T extends Activity> |
launchActivityWithIntent(String pkg,
Class<T> activityCls,
Intent intent)
Utility method for launching an activity with a specific Intent.
|
protected void |
runTest()
Runs the current unit test.
|
void |
runTestOnUiThread(Runnable r)
Helper for running portions of a test on the UI thread.
|
void |
sendKeys(int... keys)
Sends a series of key events through instrumentation and waits for idle.
|
void |
sendKeys(String keysSequence)
Sends a series of key events through instrumentation and waits for idle.
|
void |
sendRepeatedKeys(int... keys)
Sends a series of key events through instrumentation and waits for idle.
|
protected void |
tearDown()
Make sure all resources are cleaned up and garbage collected before moving on to the next
test.
|
public void injectInstrumentation(Instrumentation instrumentation)
instrumentation
- the instrumentation to use with this instance@Deprecated public void injectInsrumentation(Instrumentation instrumentation)
injectInstrumentation(android.app.Instrumentation)
instead.instrumentation
- the instrumentation to use with this instancepublic Instrumentation getInstrumentation()
public final <T extends Activity> T launchActivity(String pkg, Class<T> activityCls, Bundle extras)
The Intent
used to launch the Activity is:
action = Intent.ACTION_MAIN
extras = null, unless a custom bundle is provided here
All other fields are null or empty.
NOTE: The parameter pkg must refer to the package identifier of the package hosting the activity to be launched, which is specified in the AndroidManifest.xml file. This is not necessarily the same as the java package name.
pkg
- The package hosting the activity to be launched.activityCls
- The activity class to launch.extras
- Optional extra stuff to pass to the activity.public final <T extends Activity> T launchActivityWithIntent(String pkg, Class<T> activityCls, Intent intent)
NOTE: The parameter pkg must refer to the package identifier of the package hosting the activity to be launched, which is specified in the AndroidManifest.xml file. This is not necessarily the same as the java package name.
pkg
- The package hosting the activity to be launched.activityCls
- The activity class to launch.intent
- The intent to launch withpublic void runTestOnUiThread(Runnable r) throws Throwable
UiThreadTest
, which will run the entire test method on the UI thread.
Use this method if you need to switch in and out of the UI thread to perform your test.r
- runnable containing test code in the Runnable.run()
methodThrowable
protected void runTest() throws Throwable
UiThreadTest
, the test is run on the UI thread.Throwable
public void sendKeys(String keysSequence)
keysSequence
- The sequence of keys.public void sendKeys(int... keys)
keys
- The series of key codes to send through instrumentation.public void sendRepeatedKeys(int... keys)
keys
- The series of key repeats and codes to send through instrumentation.