Adding OCMock makes Test run the main application instead of running tests

I am trying to add OCMock to my existing Cocoa project, but I am running to a strange problem that I do not see anyone else close.

I finally split it into the following: if I just add the OCMock.framework link to my project (i.e. drag it somehow into the binary link build phase) when I run the tests, the real application runs instead.

Without OCMock, the output is normal:

Test Suite 'Multiple Selected Tests' started at 2013-02-07 20:07:03 +0000 

With a link to the OC Framework (partial output):

 Error loading MyProjTests.octest/Contents/MacOS/MyProjTests Library not loaded: @rpath/OCMock.framework/Versions/A/OCMock Reason: image not found IDEBundleInjection.c: Error loading bundle '/Users/alex/Library/Developer/Xcode/DerivedData/MyProj-bqwyxyspdiudktfnjcdgibdmpgsa/Build/Products/Debug/MyProjTests.octest' 

After that, another application exit appears. While the application is running, the test move rotates on the last tab of the project navigator and does not stop until you leave the application. So the test seems to run all the time when your application is running.

Cleaning up the test host or package loader did not solve, it only created binding errors for the wrong architecture.

I am using the latest Xcode 4.6. Any help was greatly appreciated.

+6
source share
1 answer

OK, finally figured it out before I find "Submit here", so I decided that I would share the answer. The problem was that OCMock.framework was not available at runtime.

OCMock official steps just download and add to the target, but don’t tell you to add the copy phase. I added a new phase to the test target to copy the structure to the product catalog, and the tests now work fine.

It was very unexpected that the main application would start, and I hope this helps someone else.

edit:

Photos added. Everyone loves photos.

Step 1 Build Phases -> New Phase of Copy Files

Step 2 Product catalog

Step 3 enter image description here

Step 4 Success!

+13
source

All Articles