Created
July 23, 2012 20:03
-
-
Save colabug/3165888 to your computer and use it in GitHub Desktop.
Chariot Blog Android Unit Testing With Robolectric
This file contains hidden or 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 buttonClickShouldStartNewActivity() throws Exception { | |
button.performClick(); | |
Intent intent = NewActivity.createIntent(activity); | |
assertThat(activity, new StartedMatcher(intent)); | |
} |
This file contains hidden or 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 imageShouldEqualResourceDrawable() throws Exception { | |
assertThat(image.getDrawable(), | |
equalTo(getResourceDrawable(R.drawable.sun_earth))); | |
} |
This file contains hidden or 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 shouldHaveWelcomeText() throws Exception { | |
assertViewIsVisible(welcomeText); | |
} |
This file contains hidden or 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 shouldHaveHiddenButton() throws Exception { | |
assertViewIsHidden(button); | |
} | |
@Test | |
public void shouldShowButtonAfterImageClick() throws Exception { | |
image.performClick(); | |
assertViewIsVisible(button); | |
} |
This file contains hidden or 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 welcomeTextShouldEqualResource() throws Exception { | |
assertThat(welcomeText.getText().toString(), | |
equalTo(getResourceString(R.string.WELCOME_STRING))); | |
} |
This file contains hidden or 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 shouldNotBeNull() throws Exception { | |
assertNotNull(activity); | |
} |
This file contains hidden or 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 welcomeTextClickShouldToastUser() throws Exception { | |
welcomeText.performClick(); | |
assertThat(getTextOfLatestToast(), | |
equalTo(getResourceString(R.string.WELCOME_TOAST))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment