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

1

6

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.

Revelatory answered 7/2, 2013 at 20:31 Comment(0)
R
16

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!

Revelatory answered 7/2, 2013 at 20:31 Comment(1)
That's a life saver! Exactly what I was missing.Lindberg

© 2022 - 2024 — McMap. All rights reserved.