OCMock for iPhone (iOS4, XCode 3.2.3)

2019-07-01 23:35发布

I have the last version of OCMock (1.55) and XCode 3.2.3.

I have created a test bundle target in my project. What is the best way to use OCMock in my tests? When I add OCMock.framework to the test bundle, this build error appears:

  "_OBJC_CLASS_$_OCMockObject", referenced from:
  objc-class-ref-to-OCMockObject in NotificationTests.o
  ld: symbol(s) not found
  collect2: ld returned 1 exit status

3条回答
爷的心禁止访问
2楼-- · 2019-07-01 23:55

user3135374's answer mostly helped me get this going.

Additional info:

  • The SDK must be iPhone Simulator 4.0 because 3.2 has a bug that makes it unable to properly run unit tests. Many people are complaining about it. I set this as the BaseSDK for my Unit Test target.

  • You need to add Other Linker Flags "-ObjC -force_load $(PROJECT_DIR)/path/to/libOCMock.a" to your Unit Test target or else you will get a lot of runtime "unrecognized selector sent to instance" errors

  • If you want a target that has unit tests you can actually debug (set breakpoints) follow this tutorial: http://www.lostechies.com/blogs/scottdensmore/archive/2010/07/24/debugging-unit-tests-for-the-iphone-ipad.aspx

This thread on the OCMock forums has an example project you can use:

http://www.mulle-kybernetik.com/forum/viewtopic.php?f=4&t=73&p=119#p119

查看更多
霸刀☆藐视天下
4楼-- · 2019-07-02 00:06

I had the same problem, here is how i solved it :

  • Delete ocmock.framework, the copy file phase, and any search path linking to ocmock header.

  • check out the latest version from ocmock svn repo : http://svn.mulle-kybernetik.com/OCMock/trunk

  • Build the OCMockPhoneSim target

  • Copy the libOCMock.a and Headers folder in your project folder

  • add the libOCMock.a to your framework and add a link to the headers folder in your target library search path.

Then it works !

Hope this helps.

查看更多
登录 后发表回答