I'm trying to implement a simple test but my test getting failed. I couldn't see why it's failing
My test case is: Trying to click 5th position in the RecyclerView list. My test code as below.
@RunWith(AndroidJUnit4::class)
class RecyclerListActivityTest{
@Rule @JvmField
var activityRule = ActivityTestRule<RecyclerListActivity>(
RecyclerListActivity::class.java
)
@Test
fun recyclerTest(){
onView(withId(R.id.post_list)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(5,ViewActions.click()))
}
}
Error:
E/TestRunner: androidx.test.espresso.PerformException: Error performing 'androidx.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction@81f0980' on view 'with id: com.kabelash.gitrepos:id/post_list'.
at androidx.test.espresso.PerformException$Builder.build(PerformException.java:86)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:87)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:322)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:178)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:119)
Note: When I run the app it's works fine without any errors.