Android:如何在使用 espresso 进行测试时失去对 editText 的关注

Android: how to lose focus on editText when testing with espresso

我想在我的 android 应用程序中测试我的错误消息。我的错误检查仅在我的 editText 的焦点发生变化时发生。

@Test
    fun wrongFirstname(){
        onView(withId(R.id.txtFirstNameRegister)).perform(typeText(""))
        //here I need to lose my focus
        onView(withId(R.id.txtFirstNameRegister)).check(matches(hasErrorText(R.string.firstNameCheckError.toString())))
    }

据我所知,没有明确的方法可以让你失去焦点,这也不是用户可以执行的操作,因此它不包含在 espresso 中。

您当然可以使用导致失去焦点的不同方法,例如单击不同的组件:

onView(withId(R.id.some_view)).perform(click())