iPhone Application Testing slidedeck presented at the Think Vitamin iPhone App Development Conference on 28th September 2010. Discusses why you need iOS testing, automated unit testing and automated UI testing. Ties in with O'Reilly Breakdown videos available here: http://search.oreilly.com/?i=1&q=pilone+video&t1=Video&u1=q&u2=t1&facet=ContentType&act=fc_contenttype_Video
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
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
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