android / android/testing-samples

Reduce need to augment production code to make recyclerview more testable

Open
#287 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
9.3k
Forks
3.6k
PR merge metrics
No merged PRs in 30d

Description

Is this suggested best practice or can we fix this sample to provide better ways of interacting with RecyclerViews and making assertions on the viewholder?

```
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
if (position == mDataSet.size() / 2 /* calculate middle element position */) {
viewHolder.setIsInTheMiddle(true);
viewHolder.getTextView().setText(mContext.getResources().getString(R.string.middle));
} else {
viewHolder.setIsInTheMiddle(false);
viewHolder.getTextView().setText(mDataSet.get(position));
}
}
```

From : https://github.com/googlesamples/android-testing/blob/master/ui/espresso/RecyclerViewSample/app/src/androidTest/java/com/example/android/testing/espresso/RecyclerViewSample/RecyclerViewSampleTest.java

Contributor guide

Open the contributing guide

Research direction

Start with RecyclerViewSampleTest.java in the linked androidTest sample and review the onBindViewHolder implementation shown in the issue. Determine whether the sample can expose better RecyclerView interactions and ViewHolder assertions without augmenting production code; done means the tests demonstrate that approach clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.