Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Do You Enjoy Espresso in Android App Testing?

3,264 views

Published on

Watch a live presentation at http://offer.bitbar.com/do-you-enjoy-espresso-in-android-app-testing

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.

Stay tuned and join our upcoming webinars at http://bitbar.com/testing/webinars/

Published in: Technology

Do You Enjoy Espresso in Android App Testing?

  1. 1. Do You Enjoy Espresso in Android App Testing? 6 February 2014 Ville-Veikko Helppi Technical Product Manager ville-veikko.helppi@bitbar.com
  2. 2. POLL: What is your primary test automation framework? (for Android) © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 2
  3. 3. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 3
  4. 4. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 4
  5. 5. © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 5
  6. 6. Testdroid Products Complete Solution for Mobile Apps/Games Testing © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 6
  7. 7. Testdroid Pricing – No More Unpredictable App Testing Costs! © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 7
  8. 8. 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
  9. 9. POLL: Do you use/have you used Espresso? © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 9
  10. 10. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 10
  11. 11. Android Test Automation Frameworks - The Family Tree JUnit Android Instrumentation Framework Robotium Espresso UI Automator Calabash Appium © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 11
  12. 12. Android Test Automation Frameworks - The Family Tree JUnit Android Instrumentation Framework Robotium Espresso UI Automator Calabash Appium © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 12
  13. 13. Robotium – uiautomator – Espresso • 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());
  14. 14. Android Instrumentation Framework • 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
  15. 15. Espresso by Google – Basics • 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
  16. 16. Espresso by Google – Basics 2 • 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
  17. 17. How Espresso Compares to Others? 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
  18. 18. Easy-to-Learn Espresso Syntax • 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!")));
  19. 19. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 19
  20. 20. Getting Started - Requirements • 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
  21. 21. Mods in Android Manifest file • 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
  22. 22. Go to https://cloud.testdroid.com • 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
  23. 23. © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 23 com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner
  24. 24. © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 24
  25. 25. Espresso – Better with Emulators? • Emulators won’t help you to test… – User Experience and Usability – Hardware – Software – Infrastructure 0 % = the percentage of your app users that use emulator to run your app! © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 25
  26. 26. 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? © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 26
  27. 27. 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? © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 27
  28. 28. 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! © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 28
  29. 29. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 29
  30. 30. 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 © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 30
  31. 31. © Copyrights by Bitbar Technologies Ltd. 2014 All rights reserved. 31

×