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

Android UI Testing with Espresso

Xavi Rigau
December 10, 2013

Android UI Testing with Espresso

Slides for the talk I gave at Droidcon Spain 2013 & Droidcon Italy 2014 about UI testing with Google's Espresso testing API for Android

Code for this session can be found here: https://github.com/xrigau/droidcon-android-espresso

Xavi Rigau

December 10, 2013
Tweet

More Decks by Xavi Rigau

Other Decks in Programming

Transcript

  1. UI testing with Espresso
    Xavi Rigau

    View Slide

  2. Who am I?
    ✦ +Xavi Rigau – @xrigau – github.com/xrigau – [email protected]
    ✦ 23. Born in Barcelona – Living in London
    ✦ Started working on Android in 2010
    ✦ Currently working @Novoda – github.com/novoda

    View Slide

  3. Novoda

    View Slide

  4. We’re hiring!
    ✦ Software craftsmen
    ✦ Passionate people
    ✦ Open source enthusiasts
    ✦ Positions available in London and Berlin
    ✦ Send us an email: [email protected]

    View Slide

  5. Agenda
    ✦ What’s Espresso?
    ✦ Why Espresso?
    ✦ API Overview
    ✦ Practice!

    View Slide

  6. What’s Espresso?
    http://adnatomy.wordpress.com/2013/03/05/brand-positioning-nespresso/
    not
    http://www.memegen.com/meme/wtuw41

    View Slide

  7. What’s Espresso?
    ✦ “a fun little Android UI test API” – Google
    ✦ Presented during Google Test Automation Conference 2013 (1)
    ✦ Open Source – code.google.com/p/android-test-kit
    ✦ Allows writing painless UI tests with a nice interface
    ✦ Compatible with Android API 8, 10 & 15 - 19
    1. GTAC 2013: Espresso – youtu.be/T7ugmCuNxDU

    View Slide

  8. ✦ Easy to set up (1)
    ✦ Fluid API (high level, readable tests)
    ✦ Extensible (based on Matchers – create your own!)
    ✦ Fast execution (Smart Waiting – no need to sleep())
    Why Espresso?
    1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases
    http://en.wikipedia.org/wiki/Buddy_Christ

    View Slide

  9. API Overview
    onView(Matcher)
    onData(Matcher)
    withId()/withText()/etc
    is()/instanceOf()/etc
    click()/typeText()/etc
    isDisplayed()/withText()/etc
    perform(ViewAction)
    check(ViewAssertion) matches(Matcher super View>)

    View Slide

  10. API Overview
    ✦ Examples:
    • onView(withId(R.id.some_id)).check(matches(isDisplayed()));
    • onView(withId(R.id.other_id)).perform(click());
    • onData(is(someObject)).perform(click());

    View Slide

  11. Demo time!
    ✦ Espresso – $ git clone https://code.google.com/p/android-test-kit/
    ✦ droidcon-android-espresso – github.com/xrigau/droidcon-android-espresso
    ✦ $ git clone [email protected]:xrigau/droidcon-android-espresso.git
    ✦ Write some tests! (Look at the “Next steps” section in the Readme file)
    http://memegenerator.net/instance/27270106

    View Slide

  12. Bonus: Espresso 1.1
    ✦ Adds swipe left & right actions for ViewPagers
    ✦ Multi-window support! (for Dialog, AutoCompleteTextView, …)
    ✦ Contrib Library (depends on the support library - not in core)
    • Adds support for DrawerLayout
    ✦ Other improvements, bug fixes and optimisations
    Release notes: https://code.google.com/p/android-test-kit/wiki/ReleaseNotes

    View Slide

  13. Thanks!
    http://imgace.com/pic/2011/09/unhelpful-high-school-teacher-meme/

    View Slide