Skip to content

Instantly share code, notes, and snippets.

@baz8080
Last active July 25, 2017 21:11
Show Gist options
  • Save baz8080/e6b0f7d252895468bddcafc89ee7b0bc to your computer and use it in GitHub Desktop.
Save baz8080/e6b0f7d252895468bddcafc89ee7b0bc to your computer and use it in GitHub Desktop.
Snackbar testing: the less crap version
@Test
fun genericErrrorSnackbarShouldHaveExpectedText() {
// Same setup as previous example - omitting
// Simple tests same as previous example - omitting
val snackbarLayout = snackbar.view
// Now we can use standard findViewById
val snackbarTextView = snackbarLayout.findViewById<TextView>(R.id.snackbar_text)
assertThat(snackbarTextView).isNotNull()
assertThat(snackbarTextView.text).isEqualTo("Oops, the speech didn't work!")
// This Snackbar doesn't have an action. There should also be a test which
// asserts the below after show is called
val snackbarAction = snackbarLayout.findViewById<Button>(R.id.snackbar_action)
assertThat(snackbarAction).isNotNull()
assertThat(snackbarAction.hasOnClickListeners()).isFalse()
assertThat(snackbarAction.visibility).isEqualTo(View.GONE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment