{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public final class ActivityScenarioRule<A extends Activity> extends ExternalResource
| java.lang.Object | ||
| ↳ | org.junit.rules.ExternalResource | |
| ↳ | androidx.test.ext.junit.rules.ActivityScenarioRule | |
ActivityScenarioRule launches a given activity before the test starts and closes after the test.
You can access the androidx.test.core.app.ActivityScenario instance via getScenario. You may finish your activity manually in your test, it will not cause any problems and this rule does nothing after the test in such cases.
This rule is an upgraded version of the now deprecated .
This rule does not support calling scenario.getResult(). Use ActivityScenario.launchActivityForResult() when the Activity result is needed.
Example:
@Rule
public ActivityScenarioRule<MyActivity> rule =
new ActivityScenarioRule<>(MyActivity.class);
@Test
public void myTest() {
ActivityScenario<MyActivity> scenario = rule.getScenario();
// Your test code goes here.
}
Public fields |
|
|---|---|
@Nullable ActivityScenario<A> |
|
Public constructors |
|
|---|---|
ActivityScenarioRule(Class<A> activityClass)Constructs ActivityScenarioRule for a given activity class. |
|
ActivityScenarioRule(Intent startActivityIntent)Constructs ActivityScenarioRule with a given intent. |
|
ActivityScenarioRule( |
|
ActivityScenarioRule( |
|
Public methods |
|
|---|---|
ActivityScenario<A> |
Returns |
Inherited methods |
||
|---|---|---|
|
||
public ActivityScenarioRule(Class<A> activityClass)
Constructs ActivityScenarioRule for a given activity class.
| Parameters | |
|---|---|
Class<A> activityClass |
an activity class to launch |
public ActivityScenarioRule(Intent startActivityIntent)
Constructs ActivityScenarioRule with a given intent.
| Parameters | |
|---|---|
Intent startActivityIntent |
an intent to start an activity |
public ActivityScenarioRule(
Class<A> activityClass,
@Nullable Bundle activityOptions
)
| Parameters | |
|---|---|
@Nullable Bundle activityOptions |
an activity options bundle to be passed along with the intent to start activity. |
| See also | |
|---|---|
ActivityScenarioRule |
|
public ActivityScenarioRule(
Intent startActivityIntent,
@Nullable Bundle activityOptions
)
| Parameters | |
|---|---|
@Nullable Bundle activityOptions |
an activity options bundle to be passed along with the intent to start activity. |
| See also | |
|---|---|
ActivityScenarioRule |
|
public ActivityScenario<A> getScenario()
Returns ActivityScenario of the given activity class.
| Returns | |
|---|---|
ActivityScenario<A> |
a non-null |
| Throws | |
|---|---|
java.lang.NullPointerException java.lang.NullPointerException |
if you call this method while test is not running |