ui testing with espresso

17
UI testing with Espresso Xavi Rigau

Upload: droidcon-spain

Post on 15-Jan-2015

1.711 views

Category:

Technology


1 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Ui testing with espresso

UI testing with EspressoXavi Rigau

Page 2: Ui testing with espresso

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

Page 3: Ui testing with espresso

Novoda

Page 4: Ui testing with espresso

Agenda

✦ What’s Espresso?

✦ Why Espresso?

✦ API Overview

✦ Practice!

Page 5: Ui testing with espresso

What’s Espresso?

Page 6: Ui testing with espresso

What’s Espresso?not

Page 7: Ui testing with espresso

What’s Espresso?

http://adnatomy.wordpress.com/2013/03/05/brand-positioning-nespresso/

not

Page 8: Ui testing with espresso

What’s Espresso?

http://adnatomy.wordpress.com/2013/03/05/brand-positioning-nespresso/

not

http://www.memegen.com/meme/wtuw41

Page 9: Ui testing with espresso

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

Page 10: Ui testing with 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())

Why Espresso?

1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases

Page 11: Ui testing with 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())https://svpply.com/item/258647/Felt__Wire_Shop_No_Sleep_Till_Brooklynhttp://alltheragefaces.com/face/happy-epic-win

Why Espresso?

1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases

( )

Page 12: Ui testing with 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())https://svpply.com/item/258647/Felt__Wire_Shop_No_Sleep_Till_Brooklynhttp://alltheragefaces.com/face/happy-epic-win

Why Espresso?

1. Not in Maven central, use Novoda’s repo: github.com/novoda/public-mvn-repo/tree/master/releases

( )

Page 13: Ui testing with espresso

API Overview

onView(Matcher<View>)

onData(Matcher<Object>)

withId()/withText()/etc

is()/instanceOf()/etc

click()/typeText()/etc

isDisplayed()/withText()/etc

perform(ViewAction)

check(ViewAssertion) matches(Matcher<? super View>)

Page 14: Ui testing with espresso

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());

Page 15: Ui testing with espresso

Practice!✦ 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)

Page 16: Ui testing with espresso

Practice!✦ 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

Page 17: Ui testing with espresso

Thanks!

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