Skip to content

Instantly share code, notes, and snippets.

@mirokolodii
Created February 11, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirokolodii/fc816d262ac91c344659bde90c0c284e to your computer and use it in GitHub Desktop.
Save mirokolodii/fc816d262ac91c344659bde90c0c284e to your computer and use it in GitHub Desktop.
Espresso RecyclerView count test
@Test
public void FilterClickShouldChangeRecyclerViewCount() {
// Get items count before action
RecyclerView recyclerView = mActivityTestRule.getActivity().findViewById(R.id.recycler_view);
int countBefore = Objects.requireNonNull(recyclerView.getAdapter()).getItemCount();
Log.e("count", "Items count before: " + countBefore);
// Perform action
ViewInteraction actionMenuItemView = onView(
allOf(
withId(R.id.action_filter),
withContentDescription("Show Favorites")));
actionMenuItemView.perform(click());
// Verify that items count has changed
onView(withId(R.id.recycler_view))
// Instead of 'not', you can use any other hamcrest Matcher like 'is', 'lessThan' etc.
.check(new RecyclerViewItemCountAssertion(not(countBefore)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment