简体   繁体   English

如何在空的回收站视图上执行项目点击操作?

[英]How to perform item click action on an empty recycler view?

I have a recyclerview and i am trying to write Espresso tests for it.我有一个 recyclerview,我正在尝试为它编写 Espresso 测试。 The problem is it receives data from API so while testing it has no data so whenever i do this:问题是它从 API 接收数据,所以在测试时它没有数据,所以每当我这样做时:

Espresso.onView(withId(R.id.recyclerList)).perform(actionOnItemAtPosition<ViewHolder>(2, ViewActions.click()))
   

i get an exception:我得到一个例外:

androidx.test.espresso.PerformException: Error performing 'actionOnItemAtPosition performing ViewAction: single click on item at position: 2'

but when i run tests on any recyclerview with static data then it works.但是当我使用静态数据在任何 recyclerview 上运行测试时,它就可以工作了。 So is there any way to mock data into recyclerview before calling onClick or the issue is something else?那么有没有办法在调用 onClick 之前将数据模拟到 recyclerview 中,或者问题是别的什么? Please help.请帮忙。

You should register IdlingResource to make espresso wait till the API calls are complete.您应该注册IdlingResource以使 espresso 等待 API 调用完成。

If you are using OkHttp, you can use OkHttpIdligResource .如果您使用 OkHttp,则可以使用OkHttpIdligResource You can find more information on github repo.您可以在github repo 上找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM