Testing Snackbar show with Espresso
问题 Is there a way to test using Espresso that the snackbar shows up with the right text? I have a simple call to create a snackbar Snackbar.make(mView, "My text", Snackbar.LENGTH_LONG).show(); I have tried this without luck onView(withText("My text")).inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed())); 回答1: This worked for me, please try. onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("My text"))) .check