Issue
I'm new to Espresso testing, but there doesn't seem like there's any way to test drawable changes.
I have a tutorial that is an ImageView Drawable slideshow 'tucked into' a semi-transparent TextView. In my tests, I want to ensure that when the next button is pressed, the proper Drawable has been inserted into the tutorial's ImageView.
There is no default Matcher to check for Drawables, so I set out to write my own using https://stackoverflow.com/a/28785178/981242. Unfortunately, since there is no way to retrieve the id of an ImageView's active Drawable, I can't complete the matchesSafely() implementation.
This can't be the only use case for testing active Drawables. What is the tool that people normally use for situations like this?
Solution
I prefer not to compare bitmaps and instead follow this answer's advice: https://stackoverflow.com/a/14474954/1396068
When setting the image view's drawable, also store the drawable ID in its tag with setTag(R.drawable.your_drawable). Then use Espresso's withTagValue(equalTo(R.drawable.your_drawable)) matchers to check for the correct tag.
Answered By - Fabian Streitel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.