/FragmentTestRule

JUnit Rule to test a Fragment in isolation

Primary LanguageJavaApache License 2.0Apache-2.0

Fragment Test Rule

Test Fragments in isolation.

Download

androidTestImplementation 'com.21buttons:fragment-test-rule:1.1.0'
debugImplementation 'com.21buttons:fragment-test-rule-extras:1.1.0'

Usage

@Rule
public FragmentTestRule<?, FragmentWithoutActivityDependency> fragmentTestRule =
    FragmentTestRule.create(FragmentWithoutActivityDependency.class);

@Test
public void clickButton() throws Exception {
  onView(withText(R.string.button)).perform(click());

  onView(withText(R.string.button_clicked)).check(matches(isDisplayed()));
}

You can check the sample code for more examples.