Rockstar Android Testing (Mobile TechCon Munich 2014)
-
Upload
danny-preussler -
Category
Technology
-
view
1.502 -
download
4
description
Transcript of Rockstar Android Testing (Mobile TechCon Munich 2014)
![Page 1: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/1.jpg)
Danny Preussler | Groupon
Rockstar Android Testing
![Page 2: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/2.jpg)
about me
• Android Engineer @ Groupon • Lead Engineer Android @ ebay Kleinanzeigen • Team Lead Mobile @ Cortado • C++ Developer @ PSI AG • Started career as developer @ Alcatel
• Articles in: android360, mobile Technology, Java Magazin • Speaker: DroidCon.de/nl, CONFESS, Blackberry DevCon
Believer in Testing
![Page 3: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/3.jpg)
3 Sources: Internal Data; iTunes ranking for US stores available here - https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewFeature?id=500873243&mt=8&v0=www-itunes25Bcountdown-appstore
Nearly 70 million people worldwide have downloaded our mobile app to date; 9 million in Q4 2013.
One of the 25 most downloaded free apps of all time
Nearly 50% of our global transactions completed on a mobile device in December 2013
a mobile company
Our mobile app is available in 43 countries
![Page 4: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/4.jpg)
Android Testing?
Android Firewall by Uncalno, CC BY 2.0 flickr.com/photos/uncalno/8538679708
Robotium
Appium
Calabash
Robolectric
Espresso
Cloud
Crowd
Real Device?
uiautomator
monkeyrunner
Emulator
Selenium?
InstrumentationTest
![Page 5: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/5.jpg)
Rockstar Testing? • Fast! Faster! • Reliable! • Scalable!
Acrassicau 6 by Bruce Martin, CC BY 2.0, https://www.flickr.com/photos/shotbydarko/4692892946/
![Page 6: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/6.jpg)
InstrumentationTests vs uiautomator
• Base for most frameworks
• Understand the differences!
![Page 7: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/7.jpg)
Android Activity Tests
• JUnit3 Tests
• Android Project (android application)
• Tight coupling to app under test (project needed)
• Direct access to activities (find element by id)
![Page 8: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/8.jpg)
Android Activity Tests
public class MyActivityTest extends ActivityInstrumentationTestCase2<MyActivity> { ... public void testButtons() { MyActivity activity = getActivity(); Button view = (Button)
activity.findViewById(R.id.button1); assertEquals("My Button", view.getText()); }
![Page 9: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/9.jpg)
Robotium
• Based on Intrumentation Tests
• Removes complexity
• Very popular (used to be the standard)
![Page 10: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/10.jpg)
Robotium
public class SimpleActivityTest extends ActivityInstrumentationTestCase2<MyActivity> { ... public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } public void testPressButton() throws Exception { solo.clickOnButton("press me"); assertTrue(solo.waitForText("New Window"));
![Page 11: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/11.jpg)
UIAutomator
• JUnit3 Tests
• Java Project
• Simple API
• Can access everything on device a user can
• Loose coupling to app under test
![Page 12: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/12.jpg)
UIAutomator public class LaunchSettings extends UiAutomatorTestCase { public void testPressButton() throws UiObjectNotFoundException {
getUiDevice().pressHome(); ... find and start app
UiObject button = new UiObject( new UiSelector().text(“clickMe"); button.clickAndWaitForNewWindow();
![Page 13: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/13.jpg)
UIAutomator
• Blackbox Testing
• Can only access what is visible
• API 16+
![Page 14: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/14.jpg)
InstrumentationTests vs uiautomator
• Understand the differences
Device
Application Under Test
uiatuomator
Device
Instrumentaion Application Under Test
apps apps
apps
![Page 15: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/15.jpg)
Other Basics...
• Calabash: BDD Given I am a valid user And I press "Login" Then I see "Welcome to coolest app ever”
• Robolectric: unit testing
• Monkey Runner
![Page 16: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/16.jpg)
That‘s not rock star testing!
Guitar Hero!!! By JoshBerglund19, CC BY 2.0 https://www.flickr.com/photos/tyrian123/131634756
![Page 17: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/17.jpg)
What about Selenium?
• Any language
• Any test framework
• Selenium Client API (Json Wire Protocol)
• Scale and parallize via Selenium Grid
In Theory:
![Page 18: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/18.jpg)
• Used by eBay, Facebook source: https://github.com/selendroid/selendroid/blob/master/AUTHORS
• Open Source
![Page 19: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/19.jpg)
![Page 20: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/20.jpg)
Appium • Used by
Expedia, LinkedIn, Brands4friends • Rising Star • Open Source • Cross platform • Based on ui automator
![Page 21: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/21.jpg)
Rock without
Selenium?
![Page 22: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/22.jpg)
• Used by: Groupon
• Open Sourced recently
• Remote Control your tests
RoboRemote
![Page 23: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/23.jpg)
RoboRemote Architecture
Page 23
Computer/Build Server Device/Emulator
Application Under Test
RoboRemoteServer
Robotium
UIAutomatorClient
Legend Tests Groupon Test Engineering Tests Application Developer/Tester Tests Open Source
RoboRemoteClient
UIAutomatorServer
UIAutomator
Tests
![Page 24: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/24.jpg)
RoboRemote Sample
• RoboRemote: UIAutomator UiObject myLabel = new UiObject( new UiSelector() .call(“className”, ”android.widget.TextView”) .call(“text”, “My Text”)); myLabel.call(“click”);
UiObject myLabel = new UiObject( new UiSelector() .className(”android.widget.TextView”) .text(“My Text”)); myLabel.click();
• UIAutomator
![Page 25: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/25.jpg)
• Man in the Middle HTTP Proxy
with REST API
• Single war-file
• Open Sourcing planned
RoboRemote + Odo
![Page 26: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/26.jpg)
Response Override
• Custom (stub) response • Modify response contents
• Change HTTP response code
• Add Delay
Odo-ed
(…“soldOut”:“false”,…) (“soldOut”:“true”,…)
![Page 27: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/27.jpg)
RoboRemote • RoboRemote Github:
https://github.com/groupon/robo-remote • Maven:
http://search.maven.org/ - search|ga|1|roboremote
![Page 28: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/28.jpg)
This was QA view. What about developers?
![Page 29: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/29.jpg)
• Used by: Google, XING, mobile.de, eBay Kleinanzeigen
• Open Sourced October 2013 • Based on Instrumentation
Simple! Reliable! Fast!
![Page 30: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/30.jpg)
ViewMatcher ->ViewAction ->ViewAssert
Simple
![Page 31: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/31.jpg)
onView(withId(R.id.myview)) .perform(click()) .check(matches(isDisplayed()));
Simple
![Page 32: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/32.jpg)
Use Power of Hamcrest Matcher
Simple
![Page 33: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/33.jpg)
Waiting is the root of all evil!
Evil face in Ninnaji Temple, Kyoto by MrHicks46, CC BY 2.0, http://www.flickr.com/photos/teosaurio/10138704345/
![Page 34: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/34.jpg)
• No „wait()“ in Espresso API!
Speed
![Page 35: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/35.jpg)
• Instead: – Operation on UIThread – Wait until idle – Action on UI Thread – Wait until idle – Check Result
Speed
![Page 36: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/36.jpg)
• What is idle? – UI Thread – AsyncTask – ???? via IdleResource
Speed
![Page 37: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/37.jpg)
• Removed flakyness of sleeping • Improved Testrunner
Reliable
![Page 38: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/38.jpg)
Broken Blackberry by Matthew Hurst, CC BY 2.0, http://www.flickr.com/photos/skewgee/3160670483
![Page 39: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/39.jpg)
• Used by: Google, Paypal, facebook, Cisco, LinkedIn, eBay, BMW, Intel, Evernote (source http://testdroid.com/products/success-stories)
• Real devices in the cloud • Works with:
Espresso, uiautomator, Calabash, Appium, Robotium + x
![Page 40: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/40.jpg)
• Example via Gradle: ... apply plugin: 'testdroid‘ testdroid { ... deviceGroup "10_inch_tablets" deviceLanguageCode "de-DE" fullRunConfig { instrumentationRunner = “... GoogleInstrumentationTestRunner" } }
![Page 41: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/41.jpg)
Source: http://help.testdroid.com
![Page 42: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/42.jpg)
http://testdroid.com/testautomatisierung Try it and get a free shirt:
![Page 43: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/43.jpg)
So what is the ultimate
rock star test tool now?
![Page 44: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/44.jpg)
Fazit? Check your needs and your Resources!
![Page 45: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/45.jpg)
Rock Concert! By Richard Elzey, CC BY 2.0,https://www.flickr.com/photos/elzey/5728003919
Thanks!
Let’s rock test!
![Page 46: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/46.jpg)
46
mobile rockstars
• Michael Burton Creator of Roboguice Author of „Android Application Development for Dummies“
• Carlos Sessa Author of „50 Android Hacks“
https://engineering.groupon.com/
https://github.com/groupon
![Page 47: Rockstar Android Testing (Mobile TechCon Munich 2014)](https://reader034.fdocuments.us/reader034/viewer/2022042714/554a1baeb4c9058c5d8b53c0/html5/thumbnails/47.jpg)
More Links • http://developer.android.com/tools/testing/testing_ui.html • https://code.google.com/p/robotium/ • https://github.com/calabash/calabash-android • http://selendroid.io/ • https://github.com/appium/appium • https://plus.google.com/+StephanLinzner/posts/HhXutBz7tcV- • https://code.google.com/p/android-test-kit/wiki/Espresso • https://code.google.com/p/hamcrest/ • https://cloud.testdroid.com