activityScenario.onActivity {
// Do something with an Activity.
}
fragmentScenario.onFragment {
// Do something with a Fragment.
}
Unless specified, it moves to RESUMED.
// scenario is ActivityScenario or FragmentScenario.
scenario.moveToState(State.STARTED)
// scenario is ActivityScenario or FragmentScenario.
scenario.recreate()
onView(withId(R.id.my_button)).perform(click())
// scrollTo() is necessary only if the view is not displayed without scrolling.
onView(withId(R.id.my_button)).perform(scrollTo(), click())
onView(withId(R.id.my_view)).check(matches(isDisplayed())) // VISIBLE
onView(withId(R.id.my_view)).check(matches(not(isDisplayed()))) // INVISIBLE
onView(withId(R.id.my_view)).check(doesNotExist()) // GONE or does not exist.
onView(withId(R.id.my_view))
.perform(scrollTo()) // Necessary only if the view is not displayed without scrolling.
.check(matches(withText("foo")))
onView(withId(R.id.my_view))
.perform(scrollTo()) // Necessary only if the view is not displayed without scrolling.
.check(matches(withText(containsString("foo"))))
- If you see the following error when trying to run an instrumented unit test:
java.lang.TypeNotPresentException: Type http://android.support.test.runner.AndroidJUnit4 not present
- Solution
- Go to Android Studio's menu bar >
Run
>Edit Configurations
> delete all the tests.
- Go to Android Studio's menu bar >