| java.lang.Object | |
| ↳ | android.support.test.rule.ActivityTestRule<T extends android.app.Activity> |
This rule provides functional testing of a single activity. The activity under test will be
launched before each test annotated with
Test and before
methods annotated with
Before. It
will be terminated after the test is completed and methods annotated with
After are
finished. During the duration of the test you will be able to manipulate your Activity directly.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Similar to
ActivityTestRule(Class, boolean) but with "touch mode" disabled.
| |||||||||||
Similar to
ActivityTestRule(Class, boolean, boolean) but defaults to launch the
activity under test once per
Test method.
| |||||||||||
Similar to
ActivityTestRule(Class, String, int, boolean, boolean) but defaults to
launch the Activity with the default target package name
getTargetContext() and
FLAG_ACTIVITY_NEW_TASK launch flag.
| |||||||||||
Creates an
ActivityTestRule for the Activity under test.
| |||||||||||
Creates an
ActivityTestRule for the Activity under test.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Launches the Activity under test.
| |||||||||||
Helper method for running part of a method on the UI thread.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Override this method to execute any code that should run after your
Activity is
finished.
| |||||||||||
Override this method to execute any code that should run before your
Activity is
created and launched.
| |||||||||||
Override this method to set up a custom Intent as if supplied to
startActivity(Intent).
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.junit.rules.TestRule
| |||||||||||
Similar to ActivityTestRule(Class, boolean) but with "touch mode" disabled.
| activityClass | The activity under test. This must be a class in the instrumentation targetPackage specified in the AndroidManifest.xml |
|---|
Similar to ActivityTestRule(Class, boolean, boolean) but defaults to launch the
activity under test once per
Test method.
It is launched before the first
Before
method, and terminated after the last
After
method.
| activityClass | The activity under test. This must be a class in the instrumentation targetPackage specified in the AndroidManifest.xml |
|---|---|
| initialTouchMode | true if the Activity should be placed into "touch mode" when started |
Similar to ActivityTestRule(Class, String, int, boolean, boolean) but defaults to
launch the Activity with the default target package name
getTargetContext() and
FLAG_ACTIVITY_NEW_TASK launch flag.
| activityClass | The activity under test. This must be a class in the instrumentation targetPackage specified in the AndroidManifest.xml |
|---|---|
| initialTouchMode | true if the Activity should be placed into "touch mode" when started |
| launchActivity | true if the Activity should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.
|
Creates an ActivityTestRule for the Activity under test.
| activityFactory | factory to be used for creating Activity instance |
|---|---|
| initialTouchMode | true if the Activity should be placed into "touch mode" when started |
| launchActivity | true if the Activity should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.
|
Creates an ActivityTestRule for the Activity under test.
| activityClass | The activity under test. This must be a class in the instrumentation targetPackage specified in the AndroidManifest.xml |
|---|---|
| targetPackage | The name of the target package that the Activity is started
under. This value is passed down to the start Intent using
setClassName(Context, String). Can not be null. |
| launchFlags | launch flags to start the Activity under test. |
| initialTouchMode | true if the Activity should be placed into "touch mode" when started |
| launchActivity | true if the Activity should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method. |
Launches the Activity under test.
Don't call this method directly, unless you explicitly requested not to lazily launch the
Activity manually using the launchActivity flag in
ActivityTestRule(Class, boolean, boolean).
Usage:
@Test
public void customIntentToStartActivity() {
Intent intent = new Intent(Intent.ACTION_PICK);
mActivity = mActivityRule.launchActivity(intent);
}
Note: Custom start Intents provided through this method will take precedence over default
Intents that where created in the constructor and any Intent returned from
getActivityIntent(). The same override rules documented in
getActivityIntent() apply.| startIntent | The Intent that will be used to start the Activity under test. If
startIntent is null, the Intent returned by
getActivityIntent() is used. |
|---|
Helper method for running part of a method on the UI thread.
Note: In most cases it is simpler to annotate the test method withUiThreadTest.
Use this method if you need to switch in and out of the UI thread within your method.| runnable | runnable containing test code in the run() method |
|---|
| Throwable |
|---|
Override this method to execute any code that should run after your Activity is
launched, but before any test code is run including any method annotated with
Before.
Prefer
Before
over this method. This method should usually not be overwritten directly in tests and only be
used by subclasses of ActivityTestRule to get notified when the activity is created and
visible but test runs.
Override this method to set up a custom Intent as if supplied to
startActivity(Intent). Custom Intents provided by this method will
take precedence over default Intents that where created in the constructor but be overridden
by any Intents passed in through launchActivity(Intent).
The default Intent (if this method returns null or is not overwritten) is:
action = ACTION_MAIN
flags = FLAG_ACTIVITY_NEW_TASK
All other intent fields are null or empty.
If the custom Intent provided by this methods overrides any of the following fields:
setClassName(String, String)setFlags(int)
These custom values will be used to start the Activity. However, if some of these values are
not set, the default values documented in
ActivityTestRule(Class, String, int, boolean, boolean) are supplemented.
startActivity(Intent).