I had some trouble today trying to add Unit Tests to an existing project that uses CocoaPods. So I decided to do a quick writeup of how I got it working:
Create a new project called ‘BetterTodoList’
Create a new Podfile with the following contents
platform :ios, 6.0 pod 'AFNetworking'
Close BetterTodoList in XCode, and open the workspace (as instructed by CocoaPods)
Run, and see that everything still works
Write some legacy code
Realize you need Unit Tests:
- File -> New -> Target
- Choose Other -> Cocoa Touch Unit Test Bundle
- Name it “BetterTodoListTests”
Press Cmd+U. If nothing happens, check if Product > Test is grayed out in the menu. In that case, press Cmd+<, select Test and add the test using the + button.
Add the following lines to your Podfile, and re-run “pod install”
target 'BetterTodoListTests', :exclusive => true do pod 'OCMock' end
OCMock.hin one of your files and see that it’s working.
Addendum: If you still have problems because the test target cannot access the compiled objects (e.g. “Symbol Not Found” errors), select the project in the organizer, then select the Test target, go to “Bundle Loader” and add the following values for both Debug and Release: