Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Rule
- public final ActivityTestRule<YourActivity> mActivityRule = new ActivityTestRule<>(YourActivity.class);
- @Test
- public void testSample(){
- if (getRVcount() > 0){
- onView(withId(R.id.our_recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
- }
- }
- private int getRVcount(){
- RecyclerView recyclerView = (RecyclerView) mActivityRule.getActivity().findViewById(R.id.our_recycler_view);
- return recyclerView.getAdapter().getItemCount();
- }
- @Test
- fun mainActivityTest() {
- val yourRecycler = onView(
- allOf(
- childAtPosition(
- withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
- 0
- ),
- instanceOf(RecyclerView::class.java)
- )
- )
- yourRecycler.check { view, noViewFoundException ->
- noViewFoundException?.apply {
- throw this
- }
- assertTrue(view is RecyclerView &&
- view.adapter != null && view.adapter?.itemCount?:-1 > 0
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement