Test-Driven Development and Continuous Integration for iPhone
I’m working on an iOS project and would like to use test-driven development and continuous integration. I don’t believe that it’s unreasonable to ask for a development environment to support TDD and CI these days and there are some encouraging signs such as the bundling of OCUnit with XCode. I’m documenting this so that other people can collaborate and help to fill in the blanks or show us an even better way to do it:
Goal: As a developer I want to build the software completely automatically from the command-line and have that automated process fail if any test in the project fails so that I can have some confidence in the app I’m building.
I followed the instructions on the Apple Developer website
I managed to build, run and debug a separate target in the application’s xcode project that contained all the tests.
I found these command-line options for cleaning the project and building the unit tests:
xcodebuild -target UnitTests clean build
UnitTestswas the name of the “target” I created containing the tests.- I needed to issue that command-line from the root directory of xcode project.
The important remaining question: How do I run the tests in the simulator from the command-line and act on the results?
Promising scripts found (but haven’t managed to get them working in my environment)
As part of the standard iOS SDK installed under /Developer you have these scripts:
/Developer/Tools/RunPlatformUnitTestsApple tool for xcode config calling otest (seems to need lots of configuration)/Developer/Tools/otestthe raw test runner
These were found by investigating http://cocoawithlove.com/2009/12/sample-iphone-application-with-complete.html
Build and test resources to investigate
- http://developer.apple.com/library/ios/#documentation/xcode/conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html
- http://www.cimgf.com/2009/07/06/from-hacker-to-microisv-tagging-building-and-releasing/
- http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
- http://macdevcenter.com/pub/a/mac/2004/04/23/ocunit.html
- http://cocoawithlove.com/2009/12/sample-iphone-application-with-complete.html
- http://archimage.posterous.com/setting-up-a-ci-environment-for-iphoneipad-de (looks useful - hudson and simulator launching mentioned)
Acceptance test-driven development (Nice to have)
- http://developer.apple.com/mac/articles/tools/unittestingwithxcode3.html
- http://cocoawithlove.com/2009/12/sample-mac-application-with-complete.html
- http://code.google.com/p/uispec/
Misc. to be investigated
- http://www.cocoabuilder.com/archive/cocoa/224709-unit-testing-frameworks.html
- iPhoneUnitTests
- http://stackoverflow.com/questions/2002330/implementing-unit-testing-on-the-iphone
- http://archimage.posterous.com/setting-up-a-ci-environment-for-iphoneipad-de
If you can suggest ideas or a better way of going about this please get in touch.
Thanks.