Your SlideShare is downloading. ×
0
Unit and Functional                                Testing for the                               Android Platform         ...
Christopher M. Judd      President/Consultant of                                                  leader      Columbus    ...
Remarkable Ohio                                           Free                     Developed for eTech Ohio and Ohio Histo...
University System Of Ohio                                        Free                Developed for eTech Ohio and Universi...
How many of you are currently orhave developed applications for the        Android Platform?Saturday, February 19, 2011
How many of you have ever unit or     functionally tested your       Android application?Saturday, February 19, 2011
How many of you have ever     unit tested on   another platform?Saturday, February 19, 2011
Why aren’t you testing               your Android               applications?Saturday, February 19, 2011
Testing is the key toSaturday, February 19, 2011
Testing is the key to                      AgilitySaturday, February 19, 2011
Unit TestingSaturday, February 19, 2011
Unit Testing BasicsSaturday, February 19, 2011
Why Unit Test?            Improves design            Facility change and refactoring            Simplifies integration     ...
includesSaturday, February 19, 2011
Getting StartedSaturday, February 19, 2011
1.Create Android Test ProjectSaturday, February 19, 2011
CreateAndroid Test ProjectSaturday, February 19, 2011
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="c...
Running Unit TestsSaturday, February 19, 2011
Running               Run As > Android JUnit TestSaturday, February 19, 2011
Writing Unit TestsSaturday, February 19, 2011
Test Framework    Instrumentation controls an Android       component independently of its             normal lifecycle.Sa...
TestCasesSaturday, February 19, 2011
MocksSaturday, February 19, 2011
Functional TestingSaturday, February 19, 2011
Monkey Runner                              Monkey                              RobotiumSaturday, February 19, 2011
MonkeyRunnerSaturday, February 19, 2011
functional testing framework                              for Android applications and devicesSaturday, February 19, 2011
Saturday, February 19, 2011
monkeyrunner add_note.pySaturday, February 19, 2011
# Imports the monkeyrunner modules from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage # Connect ...
When things don’t workSaturday, February 19, 2011
When things don’t work                                       add                 MonkeyRunner.sleep(1)Saturday, February 1...
automates android application                      can run in the simulator or the device                       difficult t...
MonkeySaturday, February 19, 2011
random click stress testerSaturday, February 19, 2011
adb shell monkey -p com.example.android.notepad -v 500Saturday, February 19, 2011
child proofs our app                       looks for crashes                       identifies unresponsiveness             ...
RobotiumSaturday, February 19, 2011
Selenium for Android                                        Open Source                              http://code.google.co...
Setup  1. Create Android Test Project  2. Add robotium-solo-x.x.jarSaturday, February 19, 2011
public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList> {     private static final int TWO_SECONDS = ...
Running               Run As > Android JUnit TestSaturday, February 19, 2011
Command-line$ adb shell am instrument -w    com.example.android.notepad.test/android.test.InstrumentationTestRunnercom.exa...
JUnit based                        red bar/ green bar                        asserts                      can run in the s...
Android Resources                                        http://developer.android.comSaturday, February 19, 2011
Christopher M. Judd                              President/Consultant/Author                              email: cjudd@jud...
Attributions                   http://www.organicdesign.co.nz/File:Warning.svg                   http://www.flickr.com/phot...
Upcoming SlideShare
Loading in...5
×

Unit andfunctionaltestingforandroidplatform

699

Published on

UnitAndFunctionalTestingForAndroidPlatform.pdf

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
699
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Unit andfunctionaltestingforandroidplatform"

  1. 1. Unit and Functional Testing for the Android Platform Christopher M. JuddSaturday, February 19, 2011
  2. 2. Christopher M. Judd President/Consultant of leader Columbus Developer User Group (CIDUG)Saturday, February 19, 2011
  3. 3. Remarkable Ohio Free Developed for eTech Ohio and Ohio Historical CenterSaturday, February 19, 2011
  4. 4. University System Of Ohio Free Developed for eTech Ohio and University System Of OhioSaturday, February 19, 2011
  5. 5. How many of you are currently orhave developed applications for the Android Platform?Saturday, February 19, 2011
  6. 6. How many of you have ever unit or functionally tested your Android application?Saturday, February 19, 2011
  7. 7. How many of you have ever unit tested on another platform?Saturday, February 19, 2011
  8. 8. Why aren’t you testing your Android applications?Saturday, February 19, 2011
  9. 9. Testing is the key toSaturday, February 19, 2011
  10. 10. Testing is the key to AgilitySaturday, February 19, 2011
  11. 11. Unit TestingSaturday, February 19, 2011
  12. 12. Unit Testing BasicsSaturday, February 19, 2011
  13. 13. Why Unit Test? Improves design Facility change and refactoring Simplifies integration Provides executable documentationSaturday, February 19, 2011
  14. 14. includesSaturday, February 19, 2011
  15. 15. Getting StartedSaturday, February 19, 2011
  16. 16. 1.Create Android Test ProjectSaturday, February 19, 2011
  17. 17. CreateAndroid Test ProjectSaturday, February 19, 2011
  18. 18. <?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
  19. 19. Running Unit TestsSaturday, February 19, 2011
  20. 20. Running Run As > Android JUnit TestSaturday, February 19, 2011
  21. 21. Writing Unit TestsSaturday, February 19, 2011
  22. 22. Test Framework Instrumentation controls an Android component independently of its normal lifecycle.Saturday, February 19, 2011
  23. 23. TestCasesSaturday, February 19, 2011
  24. 24. MocksSaturday, February 19, 2011
  25. 25. Functional TestingSaturday, February 19, 2011
  26. 26. Monkey Runner Monkey RobotiumSaturday, February 19, 2011
  27. 27. MonkeyRunnerSaturday, February 19, 2011
  28. 28. functional testing framework for Android applications and devicesSaturday, February 19, 2011
  29. 29. Saturday, February 19, 2011
  30. 30. monkeyrunner add_note.pySaturday, February 19, 2011
  31. 31. # Imports the monkeyrunner modules from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage # Connect to the current device device = MonkeyRunner.waitForConnection() # Install package device.installPackage(bin/NotePad.apk) # Run activity device.startActivity(component=com.example.android.notepad/.NotesList) # Press the Menu button device.press(KEYCODE_MENU,DOWN_AND_UP) # Press Add Note menu item device.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 button device.press(KEYCODE_MENU,DOWN_AND_UP) # Press save menu item device.press(KEYCODE_S,DOWN_AND_UP) # Take snapshot screenshot = device.takeSnapshot() # Write snapshot to file system screenshot.writeToFile(notes_list.png,png)Saturday, February 19, 2011
  32. 32. When things don’t workSaturday, February 19, 2011
  33. 33. When things don’t work add MonkeyRunner.sleep(1)Saturday, February 19, 2011
  34. 34. automates android application can run in the simulator or the device difficult to write scripts no red bar/green bar no verification (other than screenshots) very little documentationSaturday, February 19, 2011
  35. 35. MonkeySaturday, February 19, 2011
  36. 36. random click stress testerSaturday, February 19, 2011
  37. 37. adb shell monkey -p com.example.android.notepad -v 500Saturday, February 19, 2011
  38. 38. child proofs our app looks for crashes identifies unresponsiveness not sure the real valueSaturday, February 19, 2011
  39. 39. RobotiumSaturday, February 19, 2011
  40. 40. Selenium for Android Open Source http://code.google.com/p/robotium/Saturday, February 19, 2011
  41. 41. Setup 1. Create Android Test Project 2. Add robotium-solo-x.x.jarSaturday, February 19, 2011
  42. 42. 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
  43. 43. Running Run As > Android JUnit TestSaturday, February 19, 2011
  44. 44. Command-line$ adb shell am instrument -w com.example.android.notepad.test/android.test.InstrumentationTestRunnercom.example.android.notepad.NotePadTest:.Test results for InstrumentationTestRunner=.Time: 14.517OK (1 test)Saturday, February 19, 2011
  45. 45. JUnit based red bar/ green bar asserts can run in the simulator or the device command-line automation integrates with cucumber little documentation not approachable by traditional testersSaturday, February 19, 2011
  46. 46. Android Resources http://developer.android.comSaturday, February 19, 2011
  47. 47. Christopher M. Judd President/Consultant/Author email: cjudd@juddsolutions.com web: www.juddsolutions.com blog: juddsolutions.blogspot.com twitter: javajuddSaturday, February 19, 2011
  48. 48. Attributions http://www.organicdesign.co.nz/File:Warning.svg http://www.flickr.com/photos/heliotrop3/4310957752/Saturday, February 19, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×