Last active
February 4, 2018 18:02
-
-
Save mohsenoid/2400b492e7533ed9c3e500cdbe9af9c6 to your computer and use it in GitHub Desktop.
Sample Robolectric UI Test https://hackernoon.com/yet-another-mvp-article-part-5-writing-test-using-a-mixture-of-dagger-and-espresso-15c638182706
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
package com.mirhoseini.marvel.activity; | |
/*...*/ | |
@RunWith(RobolectricTestRunner.class) | |
@Config(constants = BuildConfig.class, sdk = 21, shadows = {ShadowSnackbar.class}) | |
public class MainActivityRobolectricTest { | |
private final static String TEST_TEXT = "This is a test text."; | |
private MainActivity activity; | |
@Before | |
public void setUp() throws Exception { | |
activity = Robolectric.setupActivity(MainActivity.class); | |
assertNotNull(activity); | |
} | |
@Test | |
public void testShowToastMessage() throws Exception { | |
activity.showMessage(TEST_TEXT); | |
assertThat(TEST_TEXT, equalTo(ShadowToast.getTextOfLatestToast())); | |
} | |
@Test | |
public void testShowOfflineMessage() throws Exception { | |
activity.showOfflineMessage(); | |
assertSnackbarIsShown(R.string.offline_message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment