Skip to content

Instantly share code, notes, and snippets.

@fo2rist
Last active June 18, 2019 02:39
Show Gist options
  • Save fo2rist/e1e2780bc25d0a31ccb1dcecc0da031b to your computer and use it in GitHub Desktop.
Save fo2rist/e1e2780bc25d0a31ccb1dcecc0da031b to your computer and use it in GitHub Desktop.
Simple Espresso Test Setup / Basic Test
@RunWith(AndroidJUnit4::class)
class BaseMainActivityTest {
@get:Rule
var activityRule = ActivityTestRule(MainActivity::class.java)
// the context is often needed in more complex Espresso tests
protected val context: Context by lazy { activityRule.activity }
@Test
fun greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"))
onView(withId(R.id.greet_button)).perform(click())
onView(withText("Hello Steve!")).check(matches(isDisplayed()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment