Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCMock Failing at runtime

I'm trying to use OCMock for the first time in my test cases. It's a Mac project, built on and targeting Lion, in Xcode 4.3. The main app and the test bundle both have ARC turned on, and so every time I execute the tests I see the following log message:

GC: forcing GC OFF because OBJC_DISABLE_GC is set

That's fine, as I'm using ARC so I don't care about GC. When I build my unit tests, linked against the latest stable release of OCMock (2.0.1), the build has no issues. At runtime, after the above log statement, I get the following:

The test bundle at /Users/___/Library/Developer/Xcode/DerivedData/___-ayizwpehemunvodsdvczckkvarsh/Build/Products/Debug/___Tests.octest could not be loaded because its Objective-C runtime information does not match the runtime information required by the test rig. This is likely because the test rig is being run with Objective-C garbage collection disabled, but the test bundle requires Objective-C garbage collection. To enable Objective-C garbage collection for the test rig, run it in an environment without the OBJC_DISABLE_GC environment variable. 2012-03-06 10:29:32.812 otest[8486:203] *** NSTask: Task create for path '/Users/___/Library/Developer/Xcode/DerivedData/___-ayizwpehemunvodsdvczckkvarsh/Build/Products/Debug/___Tests.octest/Contents/MacOS/___Tests' failed: 22, "Invalid argument". Terminating temporary process.

The message implies that garbage collection is the most common culprit, but as mentioned, there is no way I'm using GC. So, what other settings could be messing me up at runtime? I didn't think I'm doing anything atypical, and I've looked through my test project's settings to be sure, and didn't see anything weird.

Update

I was able to reproduce this with a new empty project.

  1. Create a new project and have it create unit tests, with ARC enabled
  2. Clear the Test Host setting from the unit test bundle's build settings
  3. Link to the OCMock framework
  4. Execute the tests, and witness the same error I reported above

Also, when I turn off ARC and make garbage collection Required, then clang reports a mach-o linker error, so the build doesn't succeed. If I remove the link to the OCMock framework, it builds fine. This supports my initial thought that the problem lies somewhere other than garbage collection.

like image 260
Dov Avatar asked Mar 06 '12 16:03

Dov


1 Answers

I found the answer, after a day of searching everything I could think of, in the Hamcrest tutorial (reading more carefully through the OCMock tutorial linked from OCMock.org, it's mentioned there, too). For some reason, Hamcrest's and OCMock's frameworks need to be copied to the products directory. Then everything works like a charm.

  1. Go to the settings for your Tests Bundle
  2. Go to the Build Phases tab
  3. Click the Add Build Phase button, and select Add Copy Files
  4. Set the new Copy Files build phases' Destination to Products Directory
  5. Drag OCMock.framework from the project outline into the list of files for the phase
  6. Drag the Copy Files phase above the Run Script phase

Execute your tests as usual

like image 117
Dov Avatar answered Sep 23 '22 17:09

Dov