Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UI Testing With Espresso 2.0 - AndroidListener Chicago, April 2015

UI Testing With Espresso 2.0 - AndroidListener Chicago, April 2015

A fun look in to UI testing with Android. Links at the end!

Ellen Shapiro

April 16, 2015
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. UI Testing
    With Espresso 2.0
    Ellen Shapiro
    AndroidListener Chicago, April 2015

    View full-size slide

  2. Espresso: What is?
    — Open-source UI testing
    framework for Android created
    by Google.

    View full-size slide

  3. Espresso: What is?
    — Open-source UI testing
    framework for Android created
    by Google.
    — A great way to integration-test
    your application

    View full-size slide

  4. Espresso: How work?
    — Hamcrest Matchers dig
    through the view hierarchy

    View full-size slide

  5. Espresso: How work?
    — Hamcrest Matchers dig
    through the view hierarchy
    — Only considers the portions of
    the view immediately visible
    to the user

    View full-size slide

  6. Espresso: How work?
    — Hamcrest Matchers dig
    through the view hierarchy
    — Only considers the portions of
    the view immediately visible
    to the user
    — Can enter text, tap things,
    scroll, swipe out of the box

    View full-size slide

  7. Espresso: How work?
    — Hamcrest Matchers dig
    through the view hierarchy
    — Only considers the portions of
    the view immediately visible
    to the user
    — Can enter text, tap things,
    scroll, swipe out of the box
    — Create your own actions

    View full-size slide

  8. UI Testing Best Practices
    — Don't navigate through your entire UI every single
    time.

    View full-size slide

  9. UI Testing Best Practices
    — Don't navigate through your entire UI every single
    time.
    — Use class and instance Before/After methods

    View full-size slide

  10. UI Testing Best Practices
    — Don't navigate through your entire UI every single
    time.
    — Use class and instance Before/After methods
    — Create a test class for each piece of your UI

    View full-size slide

  11. UI Testing Best Practices
    — Don't navigate through your entire UI every single
    time.
    — Use class and instance Before/After methods
    — Create a test class for each piece of your UI
    — If there are things you can test without the UI, test
    them without the UI.

    View full-size slide

  12. Other Tips for UI Testing
    — Make a mock flavor, and test on it

    View full-size slide

  13. Other Tips for UI Testing
    — Make a mock flavor, and test on it
    — Feed your networking stack mock data

    View full-size slide

  14. Shameless
    Vokal Plug Alert!

    View full-size slide

  15. Other Tips for UI Testing
    — Make a mock flavor, and test on it
    — Feed your networking stack mock data (Mocktrofit)

    View full-size slide

  16. Other Tips for UI Testing
    — Make a mock flavor, and test on it
    — Feed your networking stack mock data (Mocktrofit)
    — Compare R.string string resources to what's on
    screen.

    View full-size slide

  17. Other Tips for UI Testing
    — Make a mock flavor, and test on it
    — Feed your networking stack mock data (Mocktrofit)
    — Compare R.string string resources to what's on
    screen.
    — Remember when you need to scroll!

    View full-size slide

  18. Other Tips for UI Testing
    — Make a mock flavor, and test on it
    — Feed your networking stack mock data (Mocktrofit)
    — Compare R.string string resources to what's on
    screen.
    — Remember when you need to scroll!
    — Get to a piece of your UI that's buried without having
    to tap 800 buttons yourself

    View full-size slide

  19. NOTE: If You're Using JUnit4...
    You should Bookmark Jake
    Wharton's gist for accessing the
    activity:
    https://gist.github.com/
    JakeWharton/
    1c2f2cadab2ddd97f9fb

    View full-size slide

  20. Question Time!

    View full-size slide

  21. Links Galore!
    — Quickstart: https://code.google.com/p/android-test-
    kit/wiki/EspressoStartGuide
    — Mocktrofit: https://github.com/vokal/mocktrofit
    — ActivityRule: https://gist.github.com/JakeWharton/
    1c2f2cadab2ddd97f9fb
    — My Frankenstein Sample Project: https://github.com/
    designatednerd/AndroidListenerExamples

    View full-size slide