There has been some confusion for awhile about how to get GHUnit running on the latest Xcode version(s). I had thought that these issues were resolved awhile back, but I wasn’t sure. I recently upgraded to Xcode 4.6, and I also needed to add GHUnit to one of my projects, so I thought I’d blog about my experience, see if there are still any issues, and provide some instructions if so. The bottom line is, no. GHUnit works just fine under Xcode 4.6. Read on if you’re curious about the issues I ran into, which were basically just configuration things, nothing broken in GHUnit or Xcode 4.6.
Installing GHUnit
I’m starting with an existing Xcode project, and adding GHUnit. Here’s the steps
- Add a new target to your project: use the Empty Application template, no unit tests or Core Data. Name it “GHUnit Tests” or whatever you’d like.
- Download a copy of GHUnit from Git. Expand the file if you download as zip.
- In your project, right-click Frameworks and select the Examples/MyTestable-iOS/GHUnitIOS.framework directory in the files just downloaded. Set the “Copy items into…” checkbox, and select your GHUnit Tests target (only). Verify that GHUnitIOS.framework has been added to the Frameworks group.
- Add -ObjC and -all_load to the Other Linker Flags build setting for the GHUnit Tests target.
- Delete the files (AppDelegate.h & .m) from the new GHUnit Tests group (leave Supporting Files subfolder).
- In GHUnit Tests/Supporting Files group, edit main.
- Replace the last argument to UIApplicationMain (
NSStringFromClass([AppDelegate class])) with
with @”GHUnitIOSAppDelegate”
- Delete #import “AppDelegate.h”
- Select the GHUnit Tests scheme, and run it on the simulator.
So, exactly per the instructions, no problems.
First Problem (Deployment Target setting)
Trying this now on an actual device, I encountered a problem, but not related to GHUnit. I’ve been testing my project on an iPhone 3GS, which is the device I mount on my motorcycle handlebars. By default, Xcode 4.6 sets the Deployment Target to 6.1. Since my good old 3GS is running 5.0, it doesn’t appear in the device list. Instead it just says “iOS Device”. Changing the GHUnit target’s Deployment Target setting to 5.0 fixed this problem.
Second Problem (SenTestingKit)
Now the only thing I had left to do was to add the unit tests to the GHUnit Target. I added one of the OCUnit test case files, and reran. Not surprisingly, I got an error because I hadn’t added SenTestingKit to the GHUnit Tests target. So adding it, and rerunning, I got a similar error regarding OCMock.
Third Problem (OCMock)
The test file I added uses OCMock, so I needed to add the OCMock static library, and then add the path to the OCMock headers to the Headers Search Path build setting.
Fourth Problem (Linker path to SenTestingKit)
And finally, once I had everything compiling ok, the linker had trouble finding the SenTestingKit framework. This was fixed by updating Framework Search Paths:
$(SDKROOT)/Developer/Library/Frameworks
$(DEVELOPER_LIBRARY_DIR)/Frameworks
$(SRCROOT)
Once this was done, the tests appeared and ran successfully.
Now, if only GHUnit supported Kiwi tests…