Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Tests are always "successful" after adding OCMock

I would like to use OCMock in my Cocoa project's unit tests. I have downloaded the latest version of OCMock (2.0.1) and copied the OCMock.framework into my project's directory. In Xcode, I have added the framework to the unit test target's link phase. I have then added some code that uses OCMock's classes.

From then on out, all unit tests are reported as "successful" - green light, no errors or warnings. Even after introducing STFail calls, Xcode claims "Test succeeded". Placing a breakpoint in arbitrary test methods reveals that none of them are executed.

The issue persists if I comment out the code using OCMock, including the import directives.

The issue vanishes - i.e., the STFails start failing again - when I remove OCMock from the link phase.

This is similar to another question I've asked before, but not exactly the same: In this case, the info in the Log Navigator shows no errors. What could be causing this behavior? What can I do to diagnose the matter?

like image 206
waldrumpus Avatar asked Nov 04 '22 04:11

waldrumpus


1 Answers

It turns out I was missing a Copy Files build phase for the framework, which apparently may lead to a variety of issues.

This works for me:

  1. Add a Copy Files phase to the unit test target's build phases. I positioned it right before the Run Script phase, making it the second-to-last one.
  2. Drag the OCMock.framework item from the project navigator onto the phase in order to add it; adding it using the + button doesn't work in Xcode 4.6 (maybe because frameworks are directories?).
  3. Set the phase's destination to "Frameworks".
  4. In the unit test target's build settings, look for Runpath Search Paths and add the entry @loader_path/../Frameworks.

This way, the unit test executable will be able to find the framework at runtime. Note that you can also use "Products Directory" as the destination of the Copy Files phase, in which case you can skip the fourth step.

like image 83
waldrumpus Avatar answered Nov 15 '22 09:11

waldrumpus