This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
public class MainActivityTest { | |
@Rule | |
public ActivityTestRule<MainActivity> | |
mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenBothFieldsAreFilled_andClickOnLoginButton_shouldOpenMainActivity() { | |
Intents.init(); | |
onView(withId(R.id.login_username)).perform(typeText("defaultText"), closeSoftKeyboard()); | |
onView(withId(R.id.login_password)).perform(typeText("defaultText"), closeSoftKeyboard()); | |
Matcher<Intent> matcher = hasComponent(MainActivity.class.getName()); | |
ActivityResult result = new ActivityResult(Activity.RESULT_OK, null); | |
intending(matcher).respondWith(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenBothFieldsAreFilled_andClickOnLoginButton_shouldOpenMainActivity() { | |
Intents.init(); | |
onView(withId(R.id.login_username)).perform(typeText("username"), closeSoftKeyboard()); | |
onView(withId(R.id.login_password)).perform(typeText("password"), closeSoftKeyboard()); | |
Matcher<Intent> matcher = hasComponent(MainActivity.class.getName()); | |
onView(withId(R.id.login_button)).perform(click()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenBothFieldsAreFilled_andClickOnLoginButton_shouldOpenMainActivity() { | |
onView(withId(R.id.login_username)).perform(typeText("defaultText"), closeSoftKeyboard()); | |
onView(withId(R.id.login_password)).perform(typeText("defaultText"), closeSoftKeyboard()); | |
onView(withId(R.id.login_button)).perform(click()); | |
onView(withId(R.id.main_activity_container)).check(matches(isDisplayed())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenPasswordIsEmpty_andClickOnLoginButton_shouldDisplayDialog() { | |
testEmptyFieldState(R.id.login_username); | |
} | |
@Test | |
public void whenUserNameIsEmpty_andClickOnLoginButton_shouldDisplayDialog() { | |
testEmptyFieldState(R.id.login_password); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenPasswordIsEmpty_andClickOnLoginButton_shouldDisplayDialog() { | |
onView(withId(R.id.login_username)).perform(typeText("admin")); | |
onView(withId(R.id.login_button)).perform(click()); | |
onView(withText(R.string.validation_message)).check(matches(isDisplayed())); | |
onView(withText(R.string.ok)).perform(click()); | |
} | |
@Test | |
public void whenUserNameIsEmpty_andClickOnLoginButton_shouldDisplayDialog() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenAnyEditTextIsEmpty_andClickOnLoginButton_shouldDisplayDialog() { | |
onView(withId(R.id.login_username)).perform(typeText("admin")); | |
onView(withId(R.id.login_button)).perform(click()); | |
onView(withText(R.string.validation_message)).check(matches(isDisplayed())); | |
onView(withText(R.string.ok)).perform(click()); | |
onView(withId(R.id.login_username)).perform(clearText()); | |
onView(withId(R.id.login_password)).perform(typeText("pass123")); | |
onView(withId(R.id.login_button)).perform(click()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenActivityIsLaunched_shouldDisplayInitialState() { | |
onView(withId(R.id.login_image)).check(matches(isDisplayed())); | |
onView(withId(R.id.login_username)).check(matches(isDisplayed())); | |
onView(withId(R.id.login_password)).check(matches(isDisplayed())); | |
onView(withId(R.id.login_button)).check(matches(isDisplayed())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
public class LoginActivityTest { | |
@Rule | |
public ActivityTestRule<LoginActivity> | |
mActivityRule = new ActivityTestRule<>(LoginActivity.class, false, true); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2014 Julian Shen | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
NewerOlder