Wednesday, June 17, 2009

iPhone dev Stupidity 24: Unit Test Setup

* Sen:Te's guide


Configure the project

1. Add a ‘Unit Tests’ target

From the Project > New Target… menu add a Mac OS X > Cocoa > Unit Test

2. Configure ‘Unit Tests’ through its inspector:

In the ‘Build’ tab delete all ‘User-Defined Settings’ and the ‘Other Linker Flags’ setting.

In the ‘General’ tab add the Foundation and SenTestingKit frameworks

(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/Developer/Library/Frameworks/SenTestingKit.framework)

3. Make the application a dependency of ‘Unit Tests’:

In the ‘General’ tab of the application add ‘UnitTests’ as a direct dependency.
Write some tests

4. Avoid compiling tests outside of the simulator:

 #include "TargetConditionals.h" 
 #if !TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 
 // the SenTestCase implementation goes here... 
 #endif

* StackOverflow discuss:


If you right click on your unit test target and select the "get info" menu you will see your target options. At the bottom of the pane, you'll see a section called "User Defined": remove the entry containing the path to cocoa.h. I don't remember the name of this entry as I removed it, but this fixes the same problem I had before.

I also changed Base SDK to be Device - iPhone OS 2.2 and other linker flags to -framework Foundation -framework SentestingKit

No comments: