如何测试 Recycler 视图列表中的文本视图值? (浓缩咖啡)

How to test the text view value in a Recycler view list ? (with Espresso)

如何用 Espresso 测试中间的文字是开还是关?

尝试了以下方法,但没有用。 也面临这个问题

androidx.test.espresso.AmbiguousViewMatcherException: matches multiple views in the hierarchy.。因为可以看到多个 On/Off 具有相同 ID 的文本。

1 onView(withText("Lights")).check(isLeftAlignedWith(withText("On")))

2 onData(allOf(`is`(instanceOf(Adapter::class.java)), `is`("Lights"))).check( hasSibling(withText("On")))

可以参考official documentation

Instead of using the onView() method, start your search with onData() and provide a matcher against the data that is backing the view you’d like to match. Espresso will do all the work of finding the row in the Adapter object and making the item visible in the viewport.