我正在试用新的 Android 测试库 Espresso。当我尝试时:
onView(withId(R.id.gettingStarted))
测试运行良好。但是当我尝试时:
onView(withId(R.id.gettingStarted)).check(matches(isDisplayed()));
我得到一个 .NoMatchingViewException: No views in hierarchy found matching: with id: is <2131296645>
有没有人见过这样的事情?我最初的 react 是这只是一个错误,因为 Espresso 仅在 1.0 版本上。我正在使用 Android Studio 并严格按照设置说明进行操作。
最佳答案
这是预期的行为。
onView(withId(R.id.gettingStarted))
本身不执行任何操作。当您调用 perform 方法时,Espresso 会针对当前 View 层次结构运行 onView 方法中提供的匹配器 - 如果未找到匹配的 View ,则会抛出异常。
有关详细信息,请参阅入门指南:https://developer.android.com/training/testing/espresso/index.html
关于检查 Android Espresso NoMatchingViewException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19581150/