SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
Unit and Functional
                                Testing for the
                               Android Platform


                                 Christopher M. Judd


Saturday, February 19, 2011
Christopher M. Judd
      President/Consultant of

                                                  leader

      Columbus                     Developer User Group (CIDUG)




Saturday, February 19, 2011
Remarkable Ohio




                                           Free
                     Developed for eTech Ohio and Ohio Historical Center
Saturday, February 19, 2011
University System Of Ohio




                                        Free
                Developed for eTech Ohio and University System Of Ohio
Saturday, February 19, 2011
How many of you are currently or
have 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 to




Saturday, February 19, 2011
Testing is the key to




                      Agility
Saturday, February 19, 2011
Unit Testing


Saturday, February 19, 2011
Unit Testing Basics




Saturday, February 19, 2011
Why Unit Test?

            Improves design
            Facility change and refactoring
            Simplifies integration
            Provides executable documentation



Saturday, February 19, 2011
includes




Saturday, February 19, 2011
Getting Started




Saturday, February 19, 2011
1.Create Android Test Project




Saturday, February 19, 2011
Create
Android Test Project




Saturday, February 19, 2011
<?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
Running Unit Tests




Saturday, February 19, 2011
Running

               Run As > Android JUnit Test




Saturday, February 19, 2011
Writing Unit Tests




Saturday, February 19, 2011
Test Framework




    Instrumentation controls an Android
       component independently of its
             normal lifecycle.




Saturday, February 19, 2011
TestCases




Saturday, February 19, 2011
Mocks




Saturday, February 19, 2011
Functional Testing




Saturday, February 19, 2011
Monkey Runner
                              Monkey
                              Robotium




Saturday, February 19, 2011
MonkeyRunner




Saturday, February 19, 2011
functional testing framework
                              for Android applications and devices




Saturday, February 19, 2011
Saturday, February 19, 2011
monkeyrunner add_note.py




Saturday, February 19, 2011
# 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
When things don’t work




Saturday, February 19, 2011
When things don’t work


                                       add


                 MonkeyRunner.sleep(1)



Saturday, February 19, 2011
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 documentation

Saturday, February 19, 2011
Monkey




Saturday, February 19, 2011
random click stress tester




Saturday, February 19, 2011
adb shell monkey -p com.example.android.notepad -v 500




Saturday, February 19, 2011
child proofs our app
                       looks for crashes
                       identifies unresponsiveness



                      not sure the real value


Saturday, February 19, 2011
Robotium




Saturday, February 19, 2011
Selenium for Android


                                        Open Source

                              http://code.google.com/p/robotium/




Saturday, February 19, 2011
Setup

  1. Create Android Test Project
  2. Add robotium-solo-x.x.jar




Saturday, February 19, 2011
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
Running

               Run As > Android JUnit Test




Saturday, February 19, 2011
Command-line

$ 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)




Saturday, February 19, 2011
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 testers
Saturday, February 19, 2011
Android Resources




                                        http://developer.android.com


Saturday, February 19, 2011
Christopher M. Judd

                              President/Consultant/Author
                              email: cjudd@juddsolutions.com
                              web: www.juddsolutions.com
                              blog: juddsolutions.blogspot.com
                              twitter: javajudd




Saturday, February 19, 2011
Attributions
                   http://www.organicdesign.co.nz/File:Warning.svg

                   http://www.flickr.com/photos/heliotrop3/4310957752/




Saturday, February 19, 2011

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Kürzlich hochgeladen (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Empfohlen

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Unit andfunctionaltestingforandroidplatform

  • 1. Unit and Functional Testing for the Android Platform Christopher M. Judd Saturday, February 19, 2011
  • 2. Christopher M. Judd President/Consultant of leader Columbus Developer User Group (CIDUG) Saturday, February 19, 2011
  • 3. Remarkable Ohio Free Developed for eTech Ohio and Ohio Historical Center Saturday, February 19, 2011
  • 4. University System Of Ohio Free Developed for eTech Ohio and University System Of Ohio Saturday, February 19, 2011
  • 5. How many of you are currently or have developed applications for the Android Platform? Saturday, February 19, 2011
  • 6. How many of you have ever unit or functionally tested your Android application? Saturday, February 19, 2011
  • 7. How many of you have ever unit tested on another platform? Saturday, February 19, 2011
  • 8. Why aren’t you testing your Android applications? Saturday, February 19, 2011
  • 9. Testing is the key to Saturday, February 19, 2011
  • 10. Testing is the key to Agility Saturday, February 19, 2011
  • 12. Unit Testing Basics Saturday, February 19, 2011
  • 13. Why Unit Test? Improves design Facility change and refactoring Simplifies integration Provides executable documentation Saturday, February 19, 2011
  • 16. 1.Create Android Test Project Saturday, February 19, 2011
  • 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. Running Unit Tests Saturday, February 19, 2011
  • 20. Running Run As > Android JUnit Test Saturday, February 19, 2011
  • 21. Writing Unit Tests Saturday, February 19, 2011
  • 22. Test Framework Instrumentation controls an Android component independently of its normal lifecycle. Saturday, February 19, 2011
  • 26. Monkey Runner Monkey Robotium Saturday, February 19, 2011
  • 28. functional testing framework for Android applications and devices Saturday, February 19, 2011
  • 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. When things don’t work Saturday, February 19, 2011
  • 33. When things don’t work add MonkeyRunner.sleep(1) Saturday, February 19, 2011
  • 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 documentation Saturday, February 19, 2011
  • 36. random click stress tester Saturday, February 19, 2011
  • 37. adb shell monkey -p com.example.android.notepad -v 500 Saturday, February 19, 2011
  • 38. child proofs our app looks for crashes identifies unresponsiveness not sure the real value Saturday, February 19, 2011
  • 40. Selenium for Android Open Source http://code.google.com/p/robotium/ Saturday, February 19, 2011
  • 41. Setup 1. Create Android Test Project 2. Add robotium-solo-x.x.jar Saturday, February 19, 2011
  • 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. Running Run As > Android JUnit Test Saturday, February 19, 2011
  • 44. Command-line $ 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) Saturday, February 19, 2011
  • 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 testers Saturday, February 19, 2011
  • 46. Android Resources http://developer.android.com Saturday, February 19, 2011
  • 47. Christopher M. Judd President/Consultant/Author email: cjudd@juddsolutions.com web: www.juddsolutions.com blog: juddsolutions.blogspot.com twitter: javajudd Saturday, February 19, 2011
  • 48. Attributions http://www.organicdesign.co.nz/File:Warning.svg http://www.flickr.com/photos/heliotrop3/4310957752/ Saturday, February 19, 2011