Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Screen Robots: UI Tests in Espresso

359 views

Published on

Often when writing tests with Espresso you find a lot of onView, withId, perform calls scattered throughout your test methods. This takes away from the simplicity of the test, tends to be verbose and also litters resource ids everywhere. There's got to be a better way, right? Yes, there is...Screen Robots. In this presentation you will learn how to take advantage of the Screen Robot abstraction technique.

Published in: Mobile
  • Be the first to comment

  • Be the first to like this

Screen Robots: UI Tests in Espresso

  1. 1. Screen Robots @brwngrldev UI Tests in Espresso
  2. 2. 1. User Interface Testing 2. Espresso 3. Screen Robots Agenda @brwngrldev
  3. 3. UI Testing @brwngrldev UI element
  4. 4. UI Testing @brwngrldev
  5. 5. UI Testing @brwngrldev
  6. 6. Espresso • Framework • View Matchers • View Assertions • View Actions @brwngrldev
  7. 7. Usage @brwngrldev
  8. 8. Usage @brwngrldev
  9. 9. Usage @brwngrldev
  10. 10. @Test public void shouldProceedWithLoginWhenValid () { onView( withId( R.id.login_username_entry ) ) .perform( typeText( TEST_EMAIL ) ); onView( withId( R.id.login_password_entry ) ) .perform( typeText( TEST_PASSWORD ) ); onView( withId( R.id.login_button ) ) .perform( click() ); intended( hasComponent( hasShortClassName( PACKAGE_NAME ) ) ); } @brwngrldev
  11. 11. @Test public void shouldProceedWithLoginWhenValid () { onView( withId( … ) ) .perform( typeText( … ) ); onView( withId( … ) ) .perform( typeText( … ) ); onView( withId( … ) ) .perform( click() ); … } @brwngrldev
  12. 12. @Test public void shouldProceedWithLoginWhenValid () { < let’s do better /> } @brwngrldev
  13. 13. @brwngrldev
  14. 14. @Test public void shouldProceedWithLoginWhenValid () { } @brwngrldev
  15. 15. @Test public void shouldProceedWithLoginWhenValid () { withRobot( LoginScreenRobot.class ) } @brwngrldev
  16. 16. @Test public void shouldProceedWithLoginWhenValid () { withRobot( LoginScreenRobot.class ) .callLogin( TEST_EMAIL, TEST_PASSWORD ) } @brwngrldev
  17. 17. @Test public void shouldProceedWithLoginWhenValid () { withRobot( LoginScreenRobot.class ) .callLogin( TEST_EMAIL, TEST_PASSWORD ) .checkIsLoggedIn(); } @brwngrldev
  18. 18. @brwngrldev Just 3 lines of code!
  19. 19. public LoginScreenRobot callLogin (String username, String password) { } @brwngrldev Screen Robot
  20. 20. public LoginScreenRobot callLogin (String username, String password) { return enterTextIntoView ( R.id.login_username_entry, username ) } @brwngrldev Screen Robot
  21. 21. public LoginScreenRobot callLogin (String username, String password) { return enterTextIntoView ( R.id.login_username_entry, username ) .enterTextIntoView ( R.id.login_password_entry, password ) } @brwngrldev Screen Robot
  22. 22. public LoginScreenRobot callLogin (String username, String password) { return enterTextIntoView ( R.id.login_username_entry, username ) .enterTextIntoView ( R.id.login_password_entry, password ) .clickOkOnView( R.id.login_button ); } @brwngrldev Screen Robot
  23. 23. @brwngrldev
  24. 24. @brwngrldev Test Scenarios • Login with valid credentials • Login with invalid credentials • Login with bad server response • Changing the slide language • Verifying the correctness of the slide content • Entering content into a text slide
  25. 25. Summary Screen Robots User Interface Testing Espresso @brwngrldev
  26. 26. Thanks! @brwngrldev +AnnyceDavis www.adavis.info

×