Getting OCMock to Work with XCTest

October 7th, 2013

Filed under: Xcode | 1 comment

XCTest does not currently have built-in support for mock objects so you’ll need an external framework like OCMock for mock object support. OCMock versions 2.2 and later work with XCTest. I had only one problem getting OCMock to work with XCTest. When I ran my tests, I would get a warning saying that the test target did not finish. The cause of the warning is Xcode being unable to find the OCMock framework. The fix for this warning is to copy the OCMock framework to the products directory, using the following steps:

  1. Add a Copy Files build phase to the unit testing target. Choose Editor > Add Build Phase > Add Copy Files Build Phase.
  2. Add the OCMock framework to the Copy Files build phase.
  3. Set the copy destination to the Products Directory.

OCMock Copy Files Build Phase

Copying the OCMock framework to the products directory should be enough to run your XCTest tests that use OCMock.

Facebooktwittergoogle_plusredditmail

Tags: ,


One thought on “Getting OCMock to Work with XCTest

  1. Mazyod says:

    Great! I hope XCTests would include mock objects soon, though. They are a basic requirement in TDD.

Leave a Reply

Your email address will not be published. Required fields are marked *