Installing GHUnit on Xcode 4.6

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

  1. 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.
  2. Download a copy of GHUnit from Git. Expand the file if you download as zip.
  3. 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.
  4. Add -ObjC and -all_load to the Other Linker Flags build setting for the GHUnit Tests target.
  5. Delete the files (AppDelegate.h & .m) from the new GHUnit Tests group (leave Supporting Files subfolder).
  6. In GHUnit Tests/Supporting Files group, edit main.
    1. Replace the last argument to UIApplicationMain (

      NSStringFromClass([AppDelegate class])) with

      with @”GHUnitIOSAppDelegate”

    2. Delete #import “AppDelegate.h”
  7. 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…

3 thoughts on “Installing GHUnit on Xcode 4.6

  1. Thanks for this. How does one change the path for SenTestingKit framework in xcode? or any framework for that matter.
    This was fixed by updating Framework Search Paths:

    $(SDKROOT)/Developer/Library/Frameworks
    $(DEVELOPER_LIBRARY_DIR)/Frameworks
    $(SRCROOT)
    Where/how is this done??

  2. To anyone interested in the answer to my last question,

    One way to update the framework search paths for the GHUnit target’s sentesting framework is to :
    1) search the project for $(SDKROOT)/Developer/Library/Frameworks or some substring of it
    2) This will give results that should lead you to the Frameworks Search Paths for the LogicTests Target.

    3) although this will not look like the correct address strings; if you double click on the strings swhown they will reveal the strings :
    $(SDKROOT)/Developer/Library/Frameworks
    $(DEVELOPER_LIBRARY_DIR)/Frameworks
    $(SRCROOT)
    Just what we were looking for, sort of.

    4) You can now copy and paste these strings to the comparable location for the GHUnitTests Target.

    5) I hope this helps.

Leave a Reply