testdroid: do you enjoy espresso in android app testing?

31
webinar Do You Enjoy Espresso in Android App Testing? 6 February 2014 Ville-Veikko Helppi Technical Product Manager [email protected]

Upload: bitbar

Post on 06-May-2015

1.073 views

Category:

Technology


1 download

DESCRIPTION

Interested in a presentation video? Sign up at testdroid.com/webinars-archive Majority of us love coffee but let's put that aside and focus on Espresso - by Google. This exciting new test automation framework just got open sourced and is available for app developers and testers to hammer their app UIs. Espresso has a small, predictable and easy to learn API - built on top of Android Instrumentation Framework - and you can very quickly write concise and reliable Android UI tests with it.

TRANSCRIPT

Page 1: Testdroid: Do You Enjoy Espresso in Android App Testing?

webinar

Do You Enjoy Espresso in Android App Testing?

6 February 2014

Ville-Veikko HelppiTechnical Product [email protected]

Page 2: Testdroid: Do You Enjoy Espresso in Android App Testing?

POLL:What is your primary test automation framework?

(for Android)

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

2

webinar

Page 3: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

3

Page 4: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

4

Page 5: Testdroid: Do You Enjoy Espresso in Android App Testing?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

5

FREE DEVICES

Page 6: Testdroid: Do You Enjoy Espresso in Android App Testing?

Testdroid ProductsComplete Solution for Mobile Apps/Games Testing

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

6

webinar

Page 7: Testdroid: Do You Enjoy Espresso in Android App Testing?

Testdroid Pricing– No More Unpredictable App Testing Costs!

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

7

webinar

Page 8: Testdroid: Do You Enjoy Espresso in Android App Testing?

Testdroid Blog and Webinars– Because it is important to know how to automate your testing!

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

8

webinar

Page 9: Testdroid: Do You Enjoy Espresso in Android App Testing?

POLL:Do you use/have you used

Espresso?

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

9

webinar

Page 10: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

10

Page 11: Testdroid: Do You Enjoy Espresso in Android App Testing?

Android Test Automation Frameworks - The Family Tree

webinar

JUnit

Android Instrumentation Framework

Robotium Espresso

UI Automator

Calabash

Appium

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

11

Page 12: Testdroid: Do You Enjoy Espresso in Android App Testing?

Android Test Automation Frameworks - The Family Tree

webinar

JUnit

Android Instrumentation Framework

Robotium Espresso

UI Automator

Calabash

Appium

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

12

Page 13: Testdroid: Do You Enjoy Espresso in Android App Testing?

Robotium – uiautomator – Espressowebinar

• Robotium:

• uiautomator:

• Espresso:

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

13

int index = 0;Button buttonToFind;for (Button button : solo.getCurrentViews(Button.class)) { if (button.getText().contains("the")) { index++; if (index == 5) { buttonToFind = button; break; } }}

new UiSelector().className("Button").textContains("the").index(4)

onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier(”app.name.android:id/button", null, null)))

.perform(click());

Page 14: Testdroid: Do You Enjoy Espresso in Android App Testing?

Android Instrumentation Framework

webinar

• InstrumentationTestRunner – the primary plumbing for running tests on Android

• Android Instrumentation Framework is built on top of JUnit – a standard test framework on for any Java development

• Mock objects – methods for creating mock system objects such as content, service and intent.

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

14

Page 15: Testdroid: Do You Enjoy Espresso in Android App Testing?

Espresso by Google – Basics webinar

• Light-weight abstraction (only 600 lines of code)• Easy to setup & easily extendable• Time-independent• Backward compatibility (supporting various API levels)• A custom Instrumentation Testrunner with special privileges• Works on API levels 8 (Froyo), 10 (Gingerbread), 15-19 (IJK)• Thin layer on top of Android Instrumentation Framework• Uses the Hamcrest matcher library

https://github.com/hamcrest

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

15

Page 16: Testdroid: Do You Enjoy Espresso in Android App Testing?

Espresso by Google – Basics 2webinar

• Easy API for extending the framework:– You can write new matchers: onView(myCustomMatcher<View>)– You can write new actions: perform(myCustomAction)– You can write new checks: check(myCustomAssertion)

• Reliable: Synchronizes with the UI thread• It’s fast because there is no need for any sleeps (tests run on

same millisecond when the app becomes idle)• No support for web views and missing screenshot functions• More information Espresso can be found here:

– https://code.google.com/p/android-test-kit/

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

16

Page 17: Testdroid: Do You Enjoy Espresso in Android App Testing?

How Espresso Compares to Others?webinar

Espresso Robotium uiautomator Calabash Appium

Android Yes Yes Yes Yes Yes

iOS No No No No Yes

Mobile web No Yes (Android)

Limited to x.y clicks

Hybrid(webviews)

Yes (Android & iOS)

Scripting Language

Java Java Java Roby Almost any

Test creation tools

Hierarchy Viewer

Testdroid Recorder

UI Automator viewer

CLI Appium.app

Supported API levels

8, 10, 15-19 All 16 => All All

Community Google Contributors Google Semi-Active Active

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

17

Page 18: Testdroid: Do You Enjoy Espresso in Android App Testing?

Easy-to-Learn Espresso Syntaxwebinar

• OnView

• Check if view with the text “Hello” is shown

• R class ID identifier for “Sign in” – and click on it

• Type text in text field

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

18

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;

onView(withText("Hello")).check(matches(isDisplayed()));

onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/sign_in", null, null))) .perform(click());

onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/edit", null, null)))

.perform((typeText("Testdroid is awesome!")));

Page 19: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

19

Page 20: Testdroid: Do You Enjoy Espresso in Android App Testing?

Getting Started - Requirementswebinar

• Use the latest standalone JAR from Android Test Kit page:– https://code.google.com/p/android-test-kit/

• Reference this JAR in your test project– Right click on project -> Properties -> Java Build

Path -> Add External JARs• The current version:– espresso-1.1-bundled.jar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

20

1

Page 21: Testdroid: Do You Enjoy Espresso in Android App Testing?

Mods in Android Manifest filewebinar

2• Update AndroidManifest.xml with two things:– Specify instrumentation test runner & – Include “uses-library” -> BUILD THE PACKAGE

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 21

Page 22: Testdroid: Do You Enjoy Espresso in Android App Testing?

Go to https://cloud.testdroid.com

webinar

3• Under Projects menu, create Android project• Select Full test run

• Upload your APK and test APK• Select Advanced Configuration -> Test execution -> Custom test runner

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 22

1

2

Page 23: Testdroid: Do You Enjoy Espresso in Android App Testing?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 23

com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner3

Page 24: Testdroid: Do You Enjoy Espresso in Android App Testing?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 24

4

Page 25: Testdroid: Do You Enjoy Espresso in Android App Testing?

Espresso – Better with Emulators?• Emulators won’t help you to test…– User Experience and Usability– Hardware– Software– Infrastructure

webinar

0 % = the percentage of your app users that use emulator to run your app!

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

25

Page 26: Testdroid: Do You Enjoy Espresso in Android App Testing?

Check List for Espresso Users• Testing environment as authentic as possible– Real devices <-> emulators/simulators

• Test coverage needs to be adequate– Software is not identical in all Android devices– Hardware is even more fragmented landscape

• Surrounding testing conditions (e.g. network) • Try not to build in repetitive, manual processes• Is Espresso framework that works for you?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

26

Page 27: Testdroid: Do You Enjoy Espresso in Android App Testing?

What Framework Works You The Best?• App still under development– High-level & declarative test automation frameworks

work well – More UI specific – e.g. Espresso – requires some details

about app under development• Easy to integrate with continuous integration?• Distance between use case and actual test?• What do you build: Native, Hybrid or Web app?• The technical competence in your organization?• Desired outcome from test automation?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

27

Page 28: Testdroid: Do You Enjoy Espresso in Android App Testing?

Why Espresso is A Good Choice? • Easy to Setup & Extend – Based on Standard Android Instrumentation

• Reliable: Synchronizes with the UI thread• It’s fast because there is no need for any sleeps

(tests run on same millisecond when the app becomes idle)

• Time-independent• Google!

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

28

Page 29: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

29

Page 30: Testdroid: Do You Enjoy Espresso in Android App Testing?

Agenda• Testdroid Update!• Espresso – What Are We Talking About?• Get Up and Running with Espresso – 3 Steps• Hands-On with Eclipse + Testdroid Cloud• Q&A

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

30

Page 31: Testdroid: Do You Enjoy Espresso in Android App Testing?

webinar

© Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved.

31