The Blerg Podcast Chat

I was recently a guest on The Blerg podcast. It's a podcast that focuses on the various technologies in the Android ecosystem, featuring famed developer of Action Launcher+Chris Lacy.

During our chat, we talked all about Android TV, Google's solution for streaming devices in your home. We also talked a bit about what we would love to see in the way of additions to Android TV in the future. I spent several years developing for Google TV and Android TV, it was certainly a unique experience from typical Android application development. At any rate, I wanted to share some of the highlights of our chat with you.


Testing Tricks #5 - Using Screen Robots with Espresso



In this presentation by a developer at Square: "Software Quality/Automation Testing", he discussed how they take advantage of Robots to make it easier to update tests whenever UI elements change, as well as a few additional benefits. This is a very useful abstraction technique for when you're writing large numbers of tests in Espresso. So let's look at an example of using a Screen Robot to test a simple login flow.


Before Using a Screen Robot



So the above code is how you would typically make use of Espresso, where you have multiple calls to onView() and reference the resource ids directly in each test. Two main drawbacks of this approach is that 1) if you need to change the ids in the future you have to update multiple tests, and 2) it's not very clear from first glance what you're attempting to accomplish in a given test due to the Espresso calls. So now let's look at the same example, this time using Screen Robots.


After Using a Screen Robot



Notice how the test method is more succinct and more easily conveys what we are trying to do, namely login with a given username and password and then make sure that it was a success. 

Here's the code for our LoginScreenRobot:


This allows us to have a thin abstraction layer over the Espresso calls by extending our base ScreenRobot class. Hope you found this short testing tip helpful!