Question

I'm trying to get a basic app mac app running with XCTest and OCMock. But I am getting linking errors at runtime, I have several plain XCTests that run just fine, but the OCMock test is not working (other test hidden for brevity):

#import <OCMock/OCMock.h>

- (void)testLoadingInvalidSettingsThrowsAnError
{
    id harkMock = [OCMockObject mockForClass:[Hark class]];
    [[[harkMock stub] andReturn:@"bla"] getSettingsAsRawJson];
    XCTAssertThrowsSpecificNamed([harkMock loadSettings], NSException, @"InvalidJson");
}

The error received at runtime:

2014-02-21 11:02:47.929 Hark[90819:303] Error loading /Users/chancee/Library/Developer/Xcode/DerivedData/Hark-bsndafsdxydbivhhuuuyelepegkp/Build/Products/Debug/HarkTests.xctest/Contents/MacOS/HarkTests:  dlopen(/Users/chancee/Library/Developer/Xcode/DerivedData/Hark-bsndafsdxydbivhhuuuyelepegkp/Build/Products/Debug/HarkTests.xctest/Contents/MacOS/HarkTests, 262): Library not loaded: @rpath/OCMock.framework/Versions/A/OCMock
  Referenced from: /Users/chancee/Library/Developer/Xcode/DerivedData/Hark-bsndafsdxydbivhhuuuyelepegkp/Build/Products/Debug/HarkTests.xctest/Contents/MacOS/HarkTests
  Reason: image not found

What I've done:

  1. Download the latest OCMock.framework and placed it into /Library/Frameworks
  2. For my HarkTests target in Xcode I have added OCMock in the "Link Binary With Libraries" - however it does not show up in the list of available frameworks, I have to manually navigate to it. This raises a red flag for me, but I don't know why Xcode doesn't recognise it.
  3. Compiles fine. But throws the above error at runtime (so no tests run).
Was it helpful?

Solution

The logic for finding frameworks at compile time is different from the logic for finding the framework at runtime. OCMock uses the @rpath mechanism. I would have thought that /Library/Frameworks is on the path by default. That doesn't seem to be the case. You could try to set the Runpath Search Paths build setting to include the directory into which you have installed OCMock.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top