Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Espresso to test drawable changes

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?

like image 267
nukeforum Avatar asked Nov 17 '15 17:11

nukeforum


People also ask

Does espresso support test recording?

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.

What is Espresso UI testing?

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.

How do you assert espresso?

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.


1 Answers

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.

like image 169
Fabian Streitel Avatar answered Oct 05 '22 18:10

Fabian Streitel