我用espresso编写了一个需要删除(退格)的测试用例。我出现的代码就是这样
onView(withId(R.id.testNumberEditText))
.perform(replaceText("123"))
.perform(pressKey(KeyEvent.KEYCODE_DEL))
.check { view, _ ->
assertEquals("12", (view as EditText).text.toString())
}
但是此代码不起作用,文本仍为123
。知道我在按哪个键以获得期望的结果时做错了什么吗?
答案 0 :(得分:2)
将代码更改为此:
onView(withId(R.id.etTesting))
.perform(replaceText("123"))
.perform(click())
.perform(pressKey(KeyEvent.KEYCODE_DEL))
.check(matches(withText("12")));