views:

416

answers:

3

Do I need special libraries for this, or can I just create a huge class that trys to instantiate every object of my project and test all the methods in there? How's that done in theory?

+6  A: 

Googling "unit testing iPhone" gives this excellent link as the first hit:

To sum up, Google Toolbox provides a good infrastructure for unit testing on iPhone.

Jane Sales
I use GTM for all my iPhone unit testing. He may also wish to read http://developer.apple.com/tools/unittest.html , which explains the philosophy behind OCUnit and unit tests in Xcode.
Brad Larson
Yes, thanks for that link, Brad.
Jane Sales
+2  A: 

GHUnit is awesome.

pokeb
What are extra features of GHUnit compared to GoogleToolBox framework?Regards
Quentin
+3  A: 

If you're targeting iPhone OS 2.2 or later, you can use the version of OCUnit that's bundled with Xcode. There's a good blog article by Kailoa Kadano about this on Mobile Orchard. OCUnit is a unit testing framework that's similar to the well known JUnit framework from the Java world.

You can always do "poor man's unit testing" by creating a simple test program that uses the assert() macro in the C header assert.h or the NSAssert() macros in Cocoa/Cocoa-touch. That's not a horrible way to get started doing unit testing, but I'd really recommend looking at OCUnit or another unit testing framework eventually.

Which ever way you structure your unit tests, you'll want to create a separate target in your Xcode project to build and run the tests.

Don McCaughey