unit and functional testing for android platform
TRANSCRIPT
![Page 1: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/1.jpg)
Unit and Functional Testing for the
Android Platform
Christopher M. Judd
Saturday, February 19, 2011
![Page 2: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/2.jpg)
Christopher M. JuddPresident/Consultant of
leader
Columbus Developer User Group (CIDUG)
Saturday, February 19, 2011
![Page 3: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/3.jpg)
Remarkable Ohio
Free
Developed for eTech Ohio and Ohio Historical CenterSaturday, February 19, 2011
![Page 4: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/4.jpg)
University System Of Ohio
FreeDeveloped for eTech Ohio and University System Of Ohio
Saturday, February 19, 2011
![Page 5: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/5.jpg)
How many of you are currently or have developed applications for the
Android Platform?
Saturday, February 19, 2011
![Page 6: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/6.jpg)
How many of you have ever unit or functionally tested your
Android application?
Saturday, February 19, 2011
![Page 7: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/7.jpg)
How many of you have ever unit tested on
another platform?
Saturday, February 19, 2011
![Page 8: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/8.jpg)
Why aren’t you testing your Android applications?
Saturday, February 19, 2011
![Page 9: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/9.jpg)
Testing is the key to
Saturday, February 19, 2011
![Page 10: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/10.jpg)
Testing is the key to
AgilitySaturday, February 19, 2011
![Page 11: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/11.jpg)
Unit Testing
Saturday, February 19, 2011
![Page 12: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/12.jpg)
Unit Testing Basics
Saturday, February 19, 2011
![Page 13: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/13.jpg)
Why Unit Test?
Improves designFacility change and refactoringSimplifies integrationProvides executable documentation
Saturday, February 19, 2011
![Page 14: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/14.jpg)
includes
Saturday, February 19, 2011
![Page 15: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/15.jpg)
Getting Started
Saturday, February 19, 2011
![Page 16: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/16.jpg)
1.Create Android Test Project
Saturday, February 19, 2011
![Page 17: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/17.jpg)
Create Android Test Project
Saturday, February 19, 2011
![Page 18: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/18.jpg)
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.notepad.test" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="android.test.runner" /> </application> <uses-sdk android:minSdkVersion="3" />
<instrumentation android:targetPackage="com.example.android.notepad" android:name="android.test.InstrumentationTestRunner" /> <uses-sdk android:targetSdkVersion="4" /> </manifest>
Saturday, February 19, 2011
![Page 19: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/19.jpg)
Running Unit Tests
Saturday, February 19, 2011
![Page 20: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/20.jpg)
Running
Run As > Android JUnit Test
Saturday, February 19, 2011
![Page 21: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/21.jpg)
Writing Unit Tests
Saturday, February 19, 2011
![Page 22: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/22.jpg)
Test Framework
Instrumentation controls an Android component independently of its
normal lifecycle.
Saturday, February 19, 2011
![Page 23: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/23.jpg)
TestCases
Saturday, February 19, 2011
![Page 24: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/24.jpg)
Mocks
Saturday, February 19, 2011
![Page 25: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/25.jpg)
Functional Testing
Saturday, February 19, 2011
![Page 26: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/26.jpg)
Monkey RunnerMonkeyRobotium
Saturday, February 19, 2011
![Page 27: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/27.jpg)
MonkeyRunner
Saturday, February 19, 2011
![Page 28: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/28.jpg)
functional testing framework for Android applications and devices
Saturday, February 19, 2011
![Page 29: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/29.jpg)
Saturday, February 19, 2011
![Page 30: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/30.jpg)
monkeyrunner add_note.py
Saturday, February 19, 2011
![Page 31: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/31.jpg)
# Imports the monkeyrunner modulesfrom com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
# Connect to the current devicedevice = MonkeyRunner.waitForConnection()
# Install packagedevice.installPackage('bin/NotePad.apk')
# Run activitydevice.startActivity(component='com.example.android.notepad/.NotesList')
# Press the Menu buttondevice.press('KEYCODE_MENU','DOWN_AND_UP')
# Press Add Note menu itemdevice.press('KEYCODE_A','DOWN_AND_UP')
# Type "Mobidevdays" device.press('KEYCODE_M','DOWN_AND_UP')device.press('KEYCODE_O','DOWN_AND_UP')device.press('KEYCODE_B','DOWN_AND_UP')device.press('KEYCODE_I','DOWN_AND_UP')device.press('KEYCODE_D','DOWN_AND_UP')device.press('KEYCODE_E','DOWN_AND_UP')device.press('KEYCODE_V','DOWN_AND_UP')device.press('KEYCODE_D','DOWN_AND_UP')device.press('KEYCODE_A','DOWN_AND_UP')device.press('KEYCODE_Y','DOWN_AND_UP')
# Press the Menu buttondevice.press('KEYCODE_MENU','DOWN_AND_UP')
# Press save menu itemdevice.press('KEYCODE_S','DOWN_AND_UP')
# Take snapshotscreenshot = device.takeSnapshot()
# Write snapshot to file systemscreenshot.writeToFile('notes_list.png','png')
Saturday, February 19, 2011
![Page 32: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/32.jpg)
When things don’t work
Saturday, February 19, 2011
![Page 33: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/33.jpg)
When things don’t work
MonkeyRunner.sleep(1)
add
Saturday, February 19, 2011
![Page 34: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/34.jpg)
automates android applicationcan run in the simulator or the device
difficult to write scriptsno red bar/green barno verification (other than screenshots)very little documentation
Saturday, February 19, 2011
![Page 35: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/35.jpg)
Monkey
Saturday, February 19, 2011
![Page 36: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/36.jpg)
random click stress tester
Saturday, February 19, 2011
![Page 37: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/37.jpg)
adb shell monkey -p com.example.android.notepad -v 500
Saturday, February 19, 2011
![Page 38: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/38.jpg)
child proofs our applooks for crashesidentifies unresponsiveness
not sure the real value
Saturday, February 19, 2011
![Page 39: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/39.jpg)
Robotium
Saturday, February 19, 2011
![Page 40: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/40.jpg)
Selenium for Android
http://code.google.com/p/robotium/
Open Source
Saturday, February 19, 2011
![Page 41: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/41.jpg)
1. Create Android Test Project2. Add robotium-solo-x.x.jar
Setup
Saturday, February 19, 2011
![Page 42: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/42.jpg)
public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList> {
private static final int TWO_SECONDS = 2000; private Solo solo; public NotePadTest() { super("com.example.android.notepad", NotesList.class); }
protected void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); }
public void testAddNote() throws Exception {
solo.sendKey(Solo.MENU); solo.sendKey(Solo.MENU); // issue 61 solo.clickOnMenuItem("Add note"); solo.sleep(TWO_SECONDS); EditText note = (EditText) solo.getView(R.id.note); solo.clickOnView(note); solo.enterText(note, "Mobidevdays"); solo.sendKey(Solo.MENU); solo.sendKey(Solo.MENU); // issue 61 solo.clickOnMenuItem("Save");
assertTrue(solo.searchText("Mobidevdays")); }
public void tearDown() throws Exception { try { solo.finalize(); } catch (Throwable e) { e.printStackTrace(); } getActivity().finish(); super.tearDown(); }
}
Saturday, February 19, 2011
![Page 43: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/43.jpg)
Running
Run As > Android JUnit Test
Saturday, February 19, 2011
![Page 44: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/44.jpg)
$ adb shell am instrument -w com.example.android.notepad.test/android.test.InstrumentationTestRunner
com.example.android.notepad.NotePadTest:.Test results for InstrumentationTestRunner=.Time: 14.517
OK (1 test)
Command-line
Saturday, February 19, 2011
![Page 45: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/45.jpg)
JUnit basedred bar/ green barasserts
can run in the simulator or the devicecommand-line automationintegrates with cucumber
little documentationnot approachable by traditional testers
Saturday, February 19, 2011
![Page 46: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/46.jpg)
Android Resources
http://developer.android.com
Saturday, February 19, 2011
![Page 47: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/47.jpg)
President/Consultant/Authoremail: [email protected]: www.juddsolutions.comblog: juddsolutions.blogspot.comtwitter: javajudd
Christopher M. Judd
Saturday, February 19, 2011
![Page 48: Unit and Functional Testing for Android Platform](https://reader034.vdocuments.site/reader034/viewer/2022051412/54e7ab644a7959c5758b4aea/html5/thumbnails/48.jpg)
http://www.organicdesign.co.nz/File:Warning.svg
Attributions
http://www.flickr.com/photos/heliotrop3/4310957752/
Saturday, February 19, 2011