Forked from brunodles/gist:badaa6de2ad3a84138d517795f15efc7
Created
April 24, 2017 12:55
-
-
Save goodev/c8338bb1c96706b15fe7297048cbf4cc to your computer and use it in GitHub Desktop.
This is a test to show how to use expresso to check if a toast was displayed.
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
package com.github.brunodles.toastespresso; | |
import android.support.test.rule.ActivityTestRule; | |
import android.support.test.runner.AndroidJUnit4; | |
import android.test.suitebuilder.annotation.LargeTest; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static android.support.test.espresso.Espresso.onView; | |
import static android.support.test.espresso.action.ViewActions.click; | |
import static android.support.test.espresso.assertion.ViewAssertions.matches; | |
import static android.support.test.espresso.matcher.RootMatchers.withDecorView; | |
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | |
import static android.support.test.espresso.matcher.ViewMatchers.withText; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.hamcrest.CoreMatchers.not; | |
@RunWith(AndroidJUnit4.class) | |
@LargeTest | |
public class ApplicationTest { | |
@Rule | |
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); | |
@Test | |
public void shouldShowToast() { | |
onView(withText("Click on this button")).perform(click()); | |
onView(withText(R.string.toast)).inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment