Testing iPhone apps with Ruby and Cucumber

Mobile, Programming, Ruby
Location: Meeting Room B1/B4
Average rating: ***..
(3.75, 4 ratings)

This talk begins with a survey of the landscape of iPhone UI testing. We’ll discuss the work done by Dr. Nic Williams in unit-testing Objective-C code with RSpec, and by Matt Gallagher in spidering the iPhone UI with an XPath test script.

That will be a natural jumping-off point to explain why a full-fledged “GUI driver” for iPhone apps has been long in coming. We’ll look at different ways to prod at application code, and discuss the tradeoffs. Finally, I’ll introduce a simple library of Ruby glue code to connect Cucumber test scripts to the iPhone. The technique will be very basic, but just powerful enough to test a simple iPhone app.

Photo of Erin Dees

Erin Dees


Ian Dees saw his first Timex Sinclair 1000 over 20 years ago, and was instantly hooked. Since then, he’s debugged embedded assembly code using an oscilloscope, written desktop apps in C++, and joyfully employed scripting languages to make testing less painful. Ian currently writes GUI code for handheld instruments as a Software Engineer at Tektronix.

Ian is the author of the book Scripted GUI Testing With Ruby.

Comments on this page are now closed.


Picture of Erin Dees
Erin Dees
08/04/2009 3:30am PDT

Questions and answers from the audience on the day of the talk:

: Is it possible to grab live camera data from an automated script?

: Probably not with this technique. It is possible, however, to feed canned image data into your app’s test hooks as if it had come from the camera. The idea is a bit like the “faking the time” discussion starting on slide 45.

: What’s the applicability of this approach to testing games?

: Not much, alas; the code here is heavily UIKit-centric. A simple word puzzle app might be UIKit-based. But for heavily graphical games, you’re more likely to benefit from something like Google’s technique of capturing screen images (link: http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting#UI_and_State_Testing) and comparing them against a reference.

Picture of Erin Dees
Erin Dees
08/04/2009 3:30am PDT

: How do you protect the tests against changes in the GUI, like a button moving?

: For small changes like buttons moving, use the “tag” property of UIView to identify your interface elements, rather than tapping on specific screen coordinates. For more disruptive changes like using a completely different set of controls, wrap your app’s GUI in an ad-hoc API, and have your tests script say things like “delete the blog post” instead of “click the Delete link.”

: Can you use Ruby to test the individual classes of an iPhone app (in addition to testing the whole GUI)?

: Yes; see Dr. Nic’s Unit Testing iPhone apps with Ruby (link: http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest) article.

  • Intel
  • Microsoft
  • Google
  • SourceForge.net
  • Sun Microsystems
  • Facebook
  • Gear6
  • Kaltura
  • Liferay
  • MindTouch
  • MySpace.com
  • Novell, Inc.
  • Open Invention Network
  • Rackspace Cloud
  • Schooner Information Technology
  • Silicon Mechanics
  • Symbian Foundation
  • Twilio
  • WSO2
  • Yabarana Corporation

Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at the conference, contact Sharon Cordesse at scordesse@oreilly.com

Download the OSCON Sponsor/Exhibitor Prospectus

Media Partner Opportunities

Download the Media & Promotional Partner Brochure (PDF) for information on trade opportunities with O'Reilly conferences or contact mediapartners@ oreilly.com

Press and Media

For media-related inquiries, contact Maureen Jennings at maureen@oreilly.com

OSCON Newsletter

To stay abreast of conference news and to receive email notification when registration opens, please sign up for the OSCON newsletter (login required)

Contact Us

View a complete list of OSCON contacts