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 Drawable
s, 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 Drawable
s. What is the tool that people normally use for situations like this?
The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.
Espresso is an open source android user interface (UI) testing framework developed by Google. The term Espresso is of Italian origin, meaning Coffee. Espresso is a simple, efficient and flexible testing framework.
check is a method which accepts an argument of type ViewAssertion and do assertion using passed in ViewAssertion object. matches(withText(“Hello”)) returns a view assertion, which will do the real job of asserting that both actual view (found using withId) and expected view (found using withText) are one and the same.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With