7
Using OCMock with Xcode 3 in Leopard
Posted at 7:52 PM by Mitchell HashimotoI recently ran into another “programmer’s block” similar to when I was trying to get SVN working with mediatemple. So I am posting this to share my solution.
I am a big fan of unit testing, always have been, but I am not a test driven developer. I merely like including as many unit tests to test my code as possible. It makes me feel better about what I write. So, recently, with my ever-growing cocoa apps (see post below), I decided to begin including unit tests so that I feel better about the growth. Along with unit tests I needed mock objects to simulate a WebView for my models. Although the SenTeskingKit is included with XCode, OCMock, the mock object framework, is not.
Although I got unit testing working very easily following this guide here, I was having a lot of trouble getting the OCMock framework working. I first tried copying the framework into my project folder and linking it within the unit tests target, but that didn’t work. It would cause my app to hang. After checking the logs, I saw this:
/Developer/Tools/RunUnitTests:209: note: Running tests for architecture 'i386' 2008-01-07 18:50:59.461 AutoUW[2405:10b] Error loading /Users/mitchellh/Desktop/AutoUW/build/Debug/UnitTests.octest/Contents/MacOS/UnitTests: dlopen(/Users/mitchellh/Desktop/AutoUW/build/Debug/UnitTests.octest/Contents/MacOS/UnitTests, 262): Library not loaded: /Library/Frameworks/OCMock.framework/Versions/A/OCMock Referenced from: /Users/mitchellh/Desktop/AutoUW/build/Debug/UnitTests.octest/Contents/MacOS/UnitTests Reason: image not found
Even though I was adding the project directory the fallback framework path, it wasn’t searching it. I’m still not sure why. But anyways, if you follow the error and just add the OCMock.framework file to the /Library/Frameworks directory and compile, it works fine.
I hope this helped anyone else that may be having this issue.
2 comments made so far.
Erik Doernenburg Mar 18, 2008 at 6:39 pm
We’ve fixed the link path in OCMock. A new release will be out in a few days.
That release should make things easier. It’ll also allow to do quad Universal builds on Leopard.
I’m using OCMock in the CCMenu project, which show-cases another approach to dealing with libraries.

Michael James Jan 17, 2008 at 10:58 pm
I found this link that explains how to include OCMock.framework to your unit test target without putting in /Library/Frameworks:
http://www.cocoabuilder.com/archive/message/xcode/2007/5/2/13225
After adding OCMock.framework to your project (add it to the unit test target):
1. Add a Copy Files build phase to the unit test target. Set the Destination to Absolute Path and the Full Path to $(BUILT_PRODUCTS_DIR).
2. Drag the Copy Files build phase so that it’s between the Compile Sources and Link Binary With Libraries phases.
This worked for me.