SlideShare una empresa de Scribd logo
1 de 43
iPhone Application Testing
          Testing apps in the real world




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Who am I?

               Dan Pilone (dan@element84.com, @danpilone)
                     Author of Head First Software Development and
                     Head First iPhone and iPad Development
                     Developed software for NASA, Raytheon, UPS,
                     Hughes, and the Naval Research Laboratory
                     Founder of Element 84, LLC


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Standard iPhone Testing



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Automated Testing



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Why automate your tests?



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Verify your code does what
                       you think.


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Keeps your code doing it...



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Gives you license to make
                         changes


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Basic Unit Testing

               Support is built into Xcode
               Called Logic Tests by Apple
               Run as part of your build process
               Small scope for testing



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Setting up Logic Tests



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add a Unit Test Bundle




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add a Test Case




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
nts
                         E ach class represe
                         a test suite
                                                        @implementation LogicTests

                                                        - (void) testFail {
                                                        ! STFail(@”This’ll never work.”);
                                                  a
                         Each method represents start   }
                         specific test and should
                         with “test”.                                                   ber of
                                                        @end           There are a numrify code.
                                                                       assertions to ve




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Demo*


             * Xcode 3.2.4 requires a workaround source file

                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
ST* Macro Sample

                           STAssertTrue                                STAssertEqualObjects



                          STAssertFalse                                  STAssertEquals



                         STAssertThrows                                   STAssertNotNil


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Notes...

               Run at build time and not easily debuggable
               Don’t run in the real context of the app
               Can’t run on a real device
               Fully automatable in a CI environment



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Gives you license to make
                         changes


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Test Driven
          Development                                                  Requirements
                                                                                      Design   Code Test (what’s done)

                                                                                An iteration contains all the
                                                                                stages of a complete process.




               Somewhat of a misnomer
               Largely a design process
               Red, Green, Refactor...




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Test Driven Development works on a very simple cycle:



                                                            First you write a test that checks whatever functionality you’re about to
                                                            write. Obviously it fails, since you haven’t implemented the functionality
                                                            yet. This is the red stage, since your test GUI probably shows the test
                                                            in red (failing).




                                                            Next, implement the functionality to get that test to pass. That’s it. No
                                                            more. Nothing fancy. Write the simplest code you can to get your test
                                                            to pass. This is the green stage.




                                                            Finally, after your test passes, you can go back in and clean up some
                                                            things that you may have noticed while implementing your code. This
                                                            is the refactor stage. In the example for Starbuzz, you don’t have any
                                                            other code to refactor, so you can go right on to the next test.




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Demo



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Application Level Testing


               Test at the Integration Test Level
               Run on a physical device
               Build on what you know about unit testing




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Duplicate your app target




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add an App Test Bundle




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add the tests to the target




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add the test bundle




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Add a Test Case




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
-    (void) setUp {
      !    appDelegate    = [[UIApplication sharedApplication] delegate];
      !    viewController = appDelegate.rootViewController;
      !    rootView       = viewController.view;
      }

      - (void) testAppDelegate {
          STAssertNotNil(appDelegate, @"App delegate is nil!");
      }




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Notes...


               Only run on the device
               Can tempt you to expose things publicly that might be
               best left private
               Let you perform full integration and load testing




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Full Application Testing



                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
UIAutomation Testing

               JavaScript based testing using UIAutomation
               framework
               Leverages iPhone accessibility to let you automate your
               application in the simulator
               Runs inside Instruments to support profiling
               Full support for logging, screen captures, gestures,
               orientation and multitasking

                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Notes...

               Use tune_up.js
                     Provides a nice assertion and test wrapper around
                     UIAutomation
                     http://github.com/alexvollmer/tuneup_js
               Must run in Instruments making it difficult to use in a CI
               environment


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Sample test

                   test("Basic List", function(target, app) {
                   ! UIALogger.logMessage("Checking initial row count…");
                   !
                   ! mainWindow = app.mainWindow();
                   ! var topicTable = mainWindow.tableViews()[0];
                   ! var initialCount = topicTable.cells().length;
                   ! assertEquals(21, initialCount);
                   });




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Run UIAutomation in Instruments




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
More UIAutomation
          information

               Session 306 from WWDC 2010 Videos
               https://developer.apple.com/wwdc/iphone/library/
               documentation/DeveloperTools/Reference/
               UIAutomationRef/index.html




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Automate TDD and BDD
   Scenario Outline: selecting location for descriptions
      When I tap "Library"
      And I tap "Add"
      And I scroll down to "Add or Remove Descriptions"
      And I tap "Add or Remove Descriptions"
      And I tap "<description>"
      And I tap "more info"
      And I scroll picker column 1 of 1 columns up
  <body_row> rows
      Then I should see "<body_part>"

         Scenarios: all body           parts in muscle stiffness
         | description                 | body_row | body_part          |
         | Muscle stiffness            | 0        | not specified      |
         | Muscle stiffness            | 1        | right arm          |
         | Muscle stiffness            | 2        | right leg          |
         | Muscle stiffness            | 3        | right side         |
         | Muscle stiffness            | 4        | left arm           |
         | Muscle stiffness            | 5        | left leg           |
         | Muscle stiffness            | 6        | left side          |




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
iCuke

               iPhone App integration testing with Cucumber
               Includes basic set of steps for interacting with your app
               in the simulator
               Let’s you execute and test “app requirements”
               Not quite 100% there...
               Available here: http://github.com/unboxed/icuke


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Automate TDD and BDD




                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
CI with iPhone Apps

               Definitely achievable!
               Requires some setup due to code signing
               Uses xcodebuild to build your project just like Xcode
               Take advantage of tools like scan-build (Clang) and
               gcovr to generate static analysis and Cobertura reports
               Use ocunit2junit.rb to generate test reports


                 iPhone App Testing - Copyright 2010 Element 84, LLC

Thursday, June 2, 2011
Questions?

                                                                               Dan Pilone
                                                                               @danpilone
                 iPhone App Testing - Copyright 2010 Element 84, LLC
                                                                       dan@element84.com
Thursday, June 2, 2011

Más contenido relacionado

Destacado

Marketing to Europe: iPod
Marketing to Europe: iPodMarketing to Europe: iPod
Marketing to Europe: iPodJNathan
 
Mobile design matters - iOS and Android
Mobile design matters - iOS and AndroidMobile design matters - iOS and Android
Mobile design matters - iOS and AndroidLight Lin
 
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计iPhone/iPad开发讲座 第二讲 iPhone用户界面设计
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计Hao Peiqiang
 
Marketing Mix of Apple Inc
Marketing Mix of Apple IncMarketing Mix of Apple Inc
Marketing Mix of Apple IncJay Tripathy
 
HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기JungHyuk Kwon
 
Android vs ios presentation detailed slides
Android vs ios presentation detailed slidesAndroid vs ios presentation detailed slides
Android vs ios presentation detailed slidesMuhammad Arslan Khan
 
ppt on android vs iOS
ppt on android vs iOSppt on android vs iOS
ppt on android vs iOSShivam Gupta
 
iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case studyJohan Ronsse
 
Marketing Mix of Apple iPhone
Marketing Mix of Apple iPhoneMarketing Mix of Apple iPhone
Marketing Mix of Apple iPhonePratik Shah
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Destacado (11)

Marketing to Europe: iPod
Marketing to Europe: iPodMarketing to Europe: iPod
Marketing to Europe: iPod
 
Mobile design matters - iOS and Android
Mobile design matters - iOS and AndroidMobile design matters - iOS and Android
Mobile design matters - iOS and Android
 
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计iPhone/iPad开发讲座 第二讲 iPhone用户界面设计
iPhone/iPad开发讲座 第二讲 iPhone用户界面设计
 
Marketing Mix of Apple Inc
Marketing Mix of Apple IncMarketing Mix of Apple Inc
Marketing Mix of Apple Inc
 
HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기
 
Android vs ios presentation detailed slides
Android vs ios presentation detailed slidesAndroid vs ios presentation detailed slides
Android vs ios presentation detailed slides
 
ppt on android vs iOS
ppt on android vs iOSppt on android vs iOS
ppt on android vs iOS
 
iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case study
 
Ios vs android
Ios vs androidIos vs android
Ios vs android
 
Marketing Mix of Apple iPhone
Marketing Mix of Apple iPhoneMarketing Mix of Apple iPhone
Marketing Mix of Apple iPhone
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Último

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 

Último (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 

iPhone Application Testing

  • 1. iPhone Application Testing Testing apps in the real world iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 2. Who am I? Dan Pilone (dan@element84.com, @danpilone) Author of Head First Software Development and Head First iPhone and iPad Development Developed software for NASA, Raytheon, UPS, Hughes, and the Naval Research Laboratory Founder of Element 84, LLC iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 3. Standard iPhone Testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 4. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 5. Automated Testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 6. Why automate your tests? iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 7. Verify your code does what you think. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 8. Keeps your code doing it... iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 9. Gives you license to make changes iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 10. Basic Unit Testing Support is built into Xcode Called Logic Tests by Apple Run as part of your build process Small scope for testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 11. Setting up Logic Tests iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 12. Add a Unit Test Bundle iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 13. Add a Test Case iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 14. nts E ach class represe a test suite @implementation LogicTests - (void) testFail { ! STFail(@”This’ll never work.”); a Each method represents start } specific test and should with “test”. ber of @end There are a numrify code. assertions to ve iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 15. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 16. Demo* * Xcode 3.2.4 requires a workaround source file iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 17. ST* Macro Sample STAssertTrue STAssertEqualObjects STAssertFalse STAssertEquals STAssertThrows STAssertNotNil iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 18. Notes... Run at build time and not easily debuggable Don’t run in the real context of the app Can’t run on a real device Fully automatable in a CI environment iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 19. Gives you license to make changes iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 20. Test Driven Development Requirements Design Code Test (what’s done) An iteration contains all the stages of a complete process. Somewhat of a misnomer Largely a design process Red, Green, Refactor... iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 21. Test Driven Development works on a very simple cycle: First you write a test that checks whatever functionality you’re about to write. Obviously it fails, since you haven’t implemented the functionality yet. This is the red stage, since your test GUI probably shows the test in red (failing). Next, implement the functionality to get that test to pass. That’s it. No more. Nothing fancy. Write the simplest code you can to get your test to pass. This is the green stage. Finally, after your test passes, you can go back in and clean up some things that you may have noticed while implementing your code. This is the refactor stage. In the example for Starbuzz, you don’t have any other code to refactor, so you can go right on to the next test. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 22. Demo iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 23. Application Level Testing Test at the Integration Test Level Run on a physical device Build on what you know about unit testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 24. Duplicate your app target iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 25. Add an App Test Bundle iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 26. Add the tests to the target iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 27. Add the test bundle iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 28. Add a Test Case iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 29. - (void) setUp { ! appDelegate = [[UIApplication sharedApplication] delegate]; ! viewController = appDelegate.rootViewController; ! rootView = viewController.view; } - (void) testAppDelegate { STAssertNotNil(appDelegate, @"App delegate is nil!"); } iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 30. Notes... Only run on the device Can tempt you to expose things publicly that might be best left private Let you perform full integration and load testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 31. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 32. Full Application Testing iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 33. UIAutomation Testing JavaScript based testing using UIAutomation framework Leverages iPhone accessibility to let you automate your application in the simulator Runs inside Instruments to support profiling Full support for logging, screen captures, gestures, orientation and multitasking iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 34. Notes... Use tune_up.js Provides a nice assertion and test wrapper around UIAutomation http://github.com/alexvollmer/tuneup_js Must run in Instruments making it difficult to use in a CI environment iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 35. Sample test test("Basic List", function(target, app) { ! UIALogger.logMessage("Checking initial row count…"); ! ! mainWindow = app.mainWindow(); ! var topicTable = mainWindow.tableViews()[0]; ! var initialCount = topicTable.cells().length; ! assertEquals(21, initialCount); }); iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 36. Run UIAutomation in Instruments iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 37. iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 38. More UIAutomation information Session 306 from WWDC 2010 Videos https://developer.apple.com/wwdc/iphone/library/ documentation/DeveloperTools/Reference/ UIAutomationRef/index.html iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 39. Automate TDD and BDD Scenario Outline: selecting location for descriptions When I tap "Library" And I tap "Add" And I scroll down to "Add or Remove Descriptions" And I tap "Add or Remove Descriptions" And I tap "<description>" And I tap "more info" And I scroll picker column 1 of 1 columns up <body_row> rows Then I should see "<body_part>" Scenarios: all body parts in muscle stiffness | description | body_row | body_part | | Muscle stiffness | 0 | not specified | | Muscle stiffness | 1 | right arm | | Muscle stiffness | 2 | right leg | | Muscle stiffness | 3 | right side | | Muscle stiffness | 4 | left arm | | Muscle stiffness | 5 | left leg | | Muscle stiffness | 6 | left side | iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 40. iCuke iPhone App integration testing with Cucumber Includes basic set of steps for interacting with your app in the simulator Let’s you execute and test “app requirements” Not quite 100% there... Available here: http://github.com/unboxed/icuke iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 41. Automate TDD and BDD iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 42. CI with iPhone Apps Definitely achievable! Requires some setup due to code signing Uses xcodebuild to build your project just like Xcode Take advantage of tools like scan-build (Clang) and gcovr to generate static analysis and Cobertura reports Use ocunit2junit.rb to generate test reports iPhone App Testing - Copyright 2010 Element 84, LLC Thursday, June 2, 2011
  • 43. Questions? Dan Pilone @danpilone iPhone App Testing - Copyright 2010 Element 84, LLC dan@element84.com Thursday, June 2, 2011