Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding OCMock causes Test to launch main app instead of running tests

I'm trying to add OCMock to my existing Cocoa project, but am running to a strange problem that I don't see anyone else cover.

I finally isolated it to the following: if I simply add OCMock.framework reference to my project (i.e. drag it in somehow into Link Binary With Libraries build phase), when I run tests, the real app gets launched instead.

Without OCMock, the output is normal:

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

With OCMock framework link (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'

Other app output then appears as normal after this point. While the app is running, test progress is spinning on last tab of project navigator, and doesn't stop until you Quit the app. So test is supposedly in progress the whole time your app is running.

Clearing test host or bundle loader didn't solve, only produced linking errors for wrong architecture.

I'm using latest Xcode, 4.6. Any help greatly appreciated.

like image 435
SilverSideDown Avatar asked Feb 07 '13 20:02

SilverSideDown


1 Answers

OK, finally figured it out, before I hit Submit here on SO, so I figured I'd share the answer. The problem was that OCMock.framework wasn't available at runtime.

The official OCMock steps just say download and add to target, but don't tell you to add a copy phase. I added a new phase in the test target to copy the framework into the Products Directory and the tests now run fine.

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

edit:

Added pictures. Everyone loves pictures

Step 1 Build Phases -> New copy Files Phase

Step 2 Products Directory

Step 3 enter image description here

Step 4 Success!

like image 143
SilverSideDown Avatar answered Sep 24 '22 01:09

SilverSideDown