Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(AndroidJUnit4::class)
- class TestLoginRecipeActivityTest {
- @Rule
- @JvmField
- var activityRule = ActivityTestRule<TestLoginRecipeActivity>(TestLoginRecipeActivity::class.java)
- @Test
- fun should_ShowEmailEmptyError_When_EmailInputIsEmpty() {
- onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
- onView(withId(R.id.vTestLoginEmailInput)).check(matches(hasErrorText(R.string.test_login_empty_field)))
- }
- @Test
- fun should_ShowEmailInvalidError_When_EmailIsNotWellFormatted() {
- onView(withId(R.id.vTestLoginEmailInput)).perform(typeText(INVALID_EMAIL))
- onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
- onView(withId(R.id.vTestLoginEmailInput)).check(matches(hasErrorText(R.string.test_login_invalid_email)))
- }
- @Test
- fun should_ShowPasswordEmptyError_When_PasswordInputIsEmpty() {
- onView(withId(R.id.vTestLoginLoginBtn)).perform(click())
- onView(withId(R.id.vTestLoginPasswordInput)).check(matches(hasErrorText(R.string.test_login_empty_field)))
- }
- // A custom matcher to match a String resource with an error message.
- private fun hasErrorText(@StringRes errorRes: Int) = hasErrorText(activityRule.activity.getString(errorRes))
- companion object {
- const val INVALID_EMAIL = "invalid"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement