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
PRO

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 Slide

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

    View Slide

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

    View Slide

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

    View 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 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 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 Slide

  8. DEMO

    View Slide

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

    View Slide

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

    View 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

    View Slide

  12. 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 Slide

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

    View Slide

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

    View Slide

  15. Shameless
    Vokal Plug Alert!

    View Slide

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

    View 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.

    View 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!

    View Slide

  19. 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 Slide

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

    View Slide

  21. Question Time!

    View Slide

  22. 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 Slide