views:

147

answers:

4

I'm writing my first OS X Objective-C framework, but I do not know how to test it. How can I execute methods and classes in framework for testing purposes?

A: 

One possibility would be to create a new executable target that depends on and calls the framework you're using.

cobbal
+2  A: 

Make a unit test bundle target, and create test case classes in that bundle. You'll link against the OCUnit framework to get the base classes for your tests; there are a few OCUnit tutorials around, which you can find on Google.

For harder-to-test tasks, such as drawing in views, the easiest way is to make a test app and check the results yourself.

Peter Hosey
The Google Toolbox for Mac (on code.google.com) has excellent view and CALayer testing features. Essentially it allows you to automatically compare pixel-by-pixel renderings of either NSView or CALayer instances, failing if there are differences. For testing drawing/UI code, it's a godsend.
Barry Wark
+1  A: 

You can find several articles about unit testing on the blog of Chris Hanson.

mouviciel
+5  A: 

Chris Hanson's excellent set of articles on setting up unit testing for Frameworks in Xcode is a wonderful reference for testing frameworks. Their content has been largely incorporated (and supplanted) by the article, Automated Unit Testing with Xcode 3 and Objective-C, on Apples' Dev site.

Barry Wark