简体   繁体   中英

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. The problem is it receives data from API so while testing it has no data so whenever i do this:

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. So is there any way to mock data into recyclerview before calling onClick or the issue is something else? Please help.

You should register IdlingResource to make espresso wait till the API calls are complete.

If you are using OkHttp, you can use OkHttpIdligResource . You can find more information on github repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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