aiu*_*eoH 5 testing android android-espresso
我知道如何测试是否在以下内容中设置了错误文本EditText:
editText.check(matches(hasErrorText("")));
Run Code Online (Sandbox Code Playgroud)
现在我想测试一个EditText没有错误文本集.我试过这个,但它不起作用.
editText.check((matches(not(hasErrorText("")))));
Run Code Online (Sandbox Code Playgroud)
有谁知道这是怎么做到的吗?谢谢!
我不认为这可能是这样,取决于你想要什么,我会使用自定义匹配器:
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;
}
};
}
Run Code Online (Sandbox Code Playgroud)
此匹配器可以检查EditText是否没有任何错误文本集,使用它如下所示:
onView(allOf(withId(R.id.edittext), isDisplayed())).check(matches(hasNoErrorText()));
Run Code Online (Sandbox Code Playgroud)