Annyce Davis

ones and zeros

  • Home
  • Public Speaking
  • About Me
  • Courses
  • Life

Testing Tricks #5 – Using Screen Robots with Espresso

April 18, 2016 by Annyce Davis Leave a Comment

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.

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. This includes 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!

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

Filed Under: Android Tagged With: Espresso, Testing

Follow Me

What engineering leaders need to know from this year’s Google I/O

I didn't intentionally aim to create a rhyming title, but there you have it. Each year, I look forward to Google I/O like a kid going back to school. This year … [Read More...]

Talk: The Real MVP

You have an idea for a new app. You've secured buy-in from the business. What's next? The MVP. But what does it take to ship a new app these days? What are the … [Read More...]

Categories

  • Android (55)
  • Career (2)
  • Communication (4)
  • Flutter (1)
  • Git (4)
  • Gradle (4)
  • Grails (23)
  • Java (8)
  • JavaScript (6)
  • Kotlin (17)
  • Life (4)
  • Public Speaking (23)
  • RxJava (1)
  • Software Development (7)
  • Twitter (3)
  • Uncategorized (11)
  • Video Course (5)

Copyright © 2023 · Beautiful Pro Theme on Genesis Framework · WordPress · Log in