我知道如何测试是否在 EditText
中设置了错误文本:
editText.check(matches(hasErrorText("")));
现在我想测试 EditText
是否没有设置错误文本。我试过这个,但它不起作用。
editText.check((matches(not(hasErrorText("")))));
有人知道怎么做吗?谢谢!
最佳答案
我不认为这是可能的,具体取决于你想要什么,我会使用自定义匹配器:
public static Matcher<View> hasNoErrorText() {
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public void describeTo(Description description) {
description.appendText("has no error text: ");
}
@Override
protected boolean matchesSafely(EditText view) {
return view.getError() == null;
}
};
}
这个匹配器可以检查 EditText 是否没有设置任何错误文本,像这样使用它:
onView(allOf(withId(R.id.edittext), isDisplayed())).check(matches(hasNoErrorText()));
关于android - 在 Android 上使用 Espresso 测试 EditText View 是否没有设置错误文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42668617/