Created
February 11, 2019 15:45
-
-
Save mirokolodii/fc816d262ac91c344659bde90c0c284e to your computer and use it in GitHub Desktop.
Espresso RecyclerView count test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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