composeTestRule 检查至少 1 个项目存在
我有一个包含 2 个不同项目的列表。但是,如果用户接近列表末尾,则会一次又一次添加 2 个相同的项目,以创建无限滚动的感觉。
我创建了一个测试来基本上验证该项目是否存在,如下所示:
composeTestRule
.onAllNodesWithContentDescription("Home")
.assertCountEquals(2)
如您所见,这只是查找内容描述为“Home”的节点并检查它们是否为 2。
目前,这可以工作,因为屏幕尺寸很小,但是假设屏幕尺寸加倍,那么这将失败,因为 assertCountEquals(2)
需要检查 4
。
我想知道如何使这段代码变得更好,有没有一种方法可以基本上检查至少 1 个存在?
I have a list which has 2 different items. However, if the user gets close to the end of the list then the 2 same items are added again and again to create an infinite scrolling feel.
I've created a test to basically verify that the item exists like so:
composeTestRule
.onAllNodesWithContentDescription("Home")
.assertCountEquals(2)
As you can see this just finds nodes with the content description of "Home" and checks if their are 2.
Currently, this works as the screen size is small but let's say the screen size is doubled then this will fail as the assertCountEquals(2)
would need to check for 4
.
I was wondering to make this code better, is there a way to basically check that atleast 1 exists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
onAllNodes 方法返回一个数组,获取第一个元素并检查它是否存在或是否显示。
onAllNodes methods return an array, grab the first element and check whether it exists or is displayed.