android / android/android-test
Espresso.onData documentation fails to explain how to use the method due to vague reference to "data object"
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
The documentation for this method references an entity known as a "data object". However, the method does not provide hints, clues, further leads or information about what a "data object" is.
See https://developer.android.com/reference/android/support/test/espresso/Espresso?hl=en#ondata. Snapshot stored at https://web.archive.org/web/20190530190505/https://developer.android.com/reference/android/support/test/espresso/Espresso?hl=en
The documentation for Espresso.onData is reproduced below:
====START COPY OF DOCUMENTATION===
Creates an DataInteraction for a data object displayed by the application. Use this method to load (into the view hierarchy) items from AdapterView widgets (e.g. ListView).
This method builds a DataInteraction object - it does not interact with the application under test at all. It is expected that the caller use the ViewInteraction object to perform an action or assertion.
Parameters
dataMatcher Matcher: a matcher used to find the data object.
Returns
DataInteraction a DataInteraction that will perform an action or assertion.
====END COPY OF DOCUMENTATION===
There are 2 problems with the documentation:
1. The documentation uses the term "data object". However, data object is not defined. If data object is defined elsewhere in the Android SDK documentation, the definition is not well-known.
2. Related to point 1, but the explanation for the dataMatcher parameter does not explain what the parameter is actually supposed to be. For example, I had two guesses about what such a dataMatcher is supposed to be.
a) dataMatcher is meant to match a child view of an AdapterView
b) dataMatcher is meant to match the AdapterView itself
**My recommendation:**
First, we should clearly define what "data object" actually means. This term is too vague.
Secondly, the documentation for this method would greatly benefit if we explain what the dataMatcher is actually supposed to match.
## For future readers
After hindsight and some experimentation, I discovered that a "data object" is related to the design of AdapterViews, such as ListViews. AdapterViews are designed to separate data from the UI code; whenever an AdapterView needs to add or update a child view, the AdapterView invokes the View's [Adapter.getView()](https://developer.android.com/reference/android/widget/Adapter?hl=en#getView(int,%20android.view.View,%20android.view.ViewGroup)). Usual implementations of the getView() method retrieve data from some backend resource, such as an array, List, a Cursor, etc. that is managed by the application. The objects retrieved from this backend resources are the **data objects** that this documentation refers to. Thus, the matcher passed to onData is supposed to match against these objects used by the Adapter.
Espresso is able to retrieve these data objects by calling the [Adapter.getItem](https://developer.android.com/reference/android/widget/Adapter?hl=en#getItem(int)) method. Application developers should implement the getItem method in their custom adapters so that Espresso can scan for a position in the AdapterView whose data object matches the onData matcher.
Contributor guide
Research direction
Start with the Espresso.onData documentation and review the referenced Adapter.getView and Adapter.getItem APIs. Done means the documentation defines the data object and clearly explains that dataMatcher matches the objects returned by the adapter, resolving the two stated ambiguities.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100