ActivityScenarioRule


class ActivityScenarioRule<A : Activity?> : ExternalResource


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.
  }

Summary

Public constructors

ActivityScenarioRule(activityClass: Class<A!>!)

Constructs ActivityScenarioRule for a given activity class.

ActivityScenarioRule(startActivityIntent: Intent!)

Constructs ActivityScenarioRule with a given intent.

ActivityScenarioRule(activityClass: Class<A!>!, activityOptions: Bundle?)
ActivityScenarioRule(
    startActivityIntent: Intent!,
    activityOptions: Bundle?
)

Protected functions

Unit
Unit

Public properties

ActivityScenario<A!>?

Inherited functions

From org.junit.rules.ExternalResource
Statement!
apply(base: Statement!, description: Description!)

Public constructors

ActivityScenarioRule

ActivityScenarioRule(activityClass: Class<A!>!)

Constructs ActivityScenarioRule for a given activity class.

Parameters
activityClass: Class<A!>!

an activity class to launch

ActivityScenarioRule

ActivityScenarioRule(startActivityIntent: Intent!)

Constructs ActivityScenarioRule with a given intent.

Parameters
startActivityIntent: Intent!

an intent to start an activity

ActivityScenarioRule

ActivityScenarioRule(activityClass: Class<A!>!, activityOptions: Bundle?)
Parameters
activityClass: Class<A!>!

an activity class to launch

activityOptions: Bundle?

an activity options bundle to be passed along with the intent to start activity.

ActivityScenarioRule

ActivityScenarioRule(
    startActivityIntent: Intent!,
    activityOptions: Bundle?
)
Parameters
startActivityIntent: Intent!

an intent to start an activity

activityOptions: Bundle?

an activity options bundle to be passed along with the intent to start activity.

Protected functions

after

protected fun after(): Unit

before

protected fun before(): Unit

Public properties

scenario

val scenarioActivityScenario<A!>?