这适用于CustomMatcher:
public static MatcherhasTextInputLayoutErrorText(final String expectedErrorText) { return new TypeSafeMatcher () { @Override public boolean matchesSafely(View view) { if (!(view instanceof TextInputLayout)) { return false; } CharSequence error = ((TextInputLayout) view).getError(); if (error == null) { return false; } String hint = error.toString(); return expectedErrorText.equals(hint); } @Override public void describeTo(Description description) { } }; }