Ui testing with espresso

3,651 views

Published on

Ponencia ofrecida por Xavi Rigau en DroidconMAD 2013.
Sinopsis: Practical session on how to write better/faster UI Android automated tests using Google’s Espresso testing API. We will see:
– How to set it up in a project using Gradle.
– How to write tests in a real world example.
– Extending its API with custom matchers.
– A small dive into its internals.

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,651
On SlideShare
0
From Embeds
0
Number of Embeds
280
Actions
Shares
0
Downloads
42
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Ui testing with espresso

  1. 1. UI testing with Espresso Xavi Rigau
  2. 2. Who am I? ✦ +Xavi Rigau – @xrigau – github.com/xrigau ✦ 23. Born in Barcelona – Living in London ✦ Started working on Android in 2010 ✦ Currently working @Novoda – github.com/novoda
  3. 3. Novoda
  4. 4. Agenda ✦ What’s Espresso? ✦ Why Espresso? ✦ API Overview ✦ Practice!
  5. 5. What’s Espresso?
  6. 6. What’s Espresso? not
  7. 7. What’s Espresso? not http://adnatomy.wordpress.com/2013/03/05/brand-positioning-nespresso/
  8. 8. What’s Espresso? not http://adnatomy.wordpress.com/2013/03/05/brand-positioning-nespresso/ http://www.memegen.com/meme/wtuw41
  9. 9. 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
  10. 10. Why Espresso? ✦ 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()) 1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases
  11. 11. Why Espresso? () ✦ Easy to set up (1) ✦ Fluid API (high level, readable tests) ✦ Extensible (based on Matchers – create your own!) https://svpply.com/item/258647/Felt__Wire_Shop_No_Sleep_Till_Brooklyn http://alltheragefaces.com/face/happy-epic-win ✦ Fast execution (Smart Waiting – no need to sleep()) 1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases
  12. 12. Why Espresso? () ✦ Easy to set up (1) ✦ Fluid API (high level, readable tests) ✦ Extensible (based on Matchers – create your own!) https://svpply.com/item/258647/Felt__Wire_Shop_No_Sleep_Till_Brooklyn http://alltheragefaces.com/face/happy-epic-win ✦ Fast execution (Smart Waiting – no need to sleep()) 1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases
  13. 13. API Overview withId()/withText()/etc onView(Matcher<View>) perform(ViewAction) click()/typeText()/etc onData(Matcher<Object>) check(ViewAssertion) matches(Matcher<? super View>) is()/instanceOf()/etc isDisplayed()/withText()/etc
  14. 14. 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());
  15. 15. Practice! ✦ Espresso – $ git clone https://code.google.com/p/android-test-kit/ ✦ droidcon-android-espresso – github.com/xrigau/droidcon-android-espresso ✦ $ git clone git@github.com:xrigau/droidcon-android-espresso.git ✦ Write some tests! (Look at the “Next steps” section in the Readme file)
  16. 16. Practice! ✦ Espresso – $ git clone https://code.google.com/p/android-test-kit/ ✦ droidcon-android-espresso – github.com/xrigau/droidcon-android-espresso ✦ $ git clone git@github.com:xrigau/droidcon-android-espresso.git ✦ Write some tests! (Look at the “Next steps” section in the Readme file) http://memegenerator.net/instance/27270106
  17. 17. Thanks! http://imgace.com/pic/2011/09/unhelpful-high-school-teacher-meme/

×