Last active
April 5, 2016 21:35
-
-
Save brunodles/603742918acbe985f9334d54b4eae0bf 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