Skip to content

What is ActivityTestRule

Devrath edited this page Jul 3, 2021 · 2 revisions

Defining ActivityTestRule

  • This rule is used to launch an activity in instrumentation testing.
  • Basically this test rule provides functional testing of a single activity.

Gradle

androidTestImplementation ‘com.android.support.test:rules:1.0.2

Usage in code

// Global declaration
@Rule
public ActivityTestRule<SampleActivity> activityRule = new ActivityTestRule<>(SampleActivity.class, true, false);

// In Each test or in the @before block
Intent i = new Intent(activityRule.getActivity(), SampleActivity.class);
activityRule.launchActivity(i);
Clone this wiki locally