Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. @RunWith(AndroidJUnit4::class)
  2. class TestLoginRecipeActivityTest {
  3.  
  4. @Rule
  5. @JvmField
  6. var activityRule = ActivityTestRule<TestLoginRecipeActivity>(TestLoginRecipeActivity::class.java)
  7.  
  8. @Test
  9. fun should_ShowEmailEmptyError_When_EmailInputIsEmpty() {
  10. onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
  11. onView(withId(R.id.vTestLoginEmailInput)).check(matches(hasErrorText(R.string.test_login_empty_field)))
  12. }
  13.  
  14. @Test
  15. fun should_ShowEmailInvalidError_When_EmailIsNotWellFormatted() {
  16. onView(withId(R.id.vTestLoginEmailInput)).perform(typeText(INVALID_EMAIL))
  17. onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
  18. onView(withId(R.id.vTestLoginEmailInput)).check(matches(hasErrorText(R.string.test_login_invalid_email)))
  19. }
  20.  
  21. @Test
  22. fun should_ShowPasswordEmptyError_When_PasswordInputIsEmpty() {
  23. onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
  24. onView(withId(R.id.vTestLoginPasswordInput)).check(matches(hasErrorText(R.string.test_login_empty_field)))
  25. }
  26.  
  27. // A custom matcher to match a String resource with an error message.
  28. private fun hasErrorText(@StringRes errorRes: Int) = hasErrorText(activityRule.activity.getString(errorRes))
  29.  
  30. companion object {
  31. const val INVALID_EMAIL = "invalid"
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement