简体   繁体   English

适用于iPhone的OCMock(iOS4,XCode 3.2.3)

[英]OCMock for iPhone (iOS4, XCode 3.2.3)

I have the last version of OCMock (1.55) and XCode 3.2.3. 我有最新版本的OCMock (1.55)和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? 在我的测试中使用OCMock的最佳方法是什么? When I add OCMock.framework to the test bundle, this build error appears: 当我将OCMock.framework添加到测试包时,会出现此生成错误:

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

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. 删除ocmock.framework,复制文件阶段以及链接到ocmock标头的任何搜索路径。

  • check out the latest version from ocmock svn repo : http://svn.mulle-kybernetik.com/OCMock/trunk 查看ocmock svn repo的最新版本: http ://svn.mulle-kybernetik.com/OCMock/trunk

  • Build the OCMockPhoneSim target 构建OCMockPhoneSim目标

  • Copy the libOCMock.a and Headers folder in your project folder 复制项目文件夹中的libOCMock.a和Headers文件夹

  • add the libOCMock.a to your framework and add a link to the headers folder in your target library search path. 将libOCMock.a添加到框架中,并添加指向目标库搜索路径中headers文件夹的链接。

Then it works ! 然后它的作品!

Hope this helps. 希望这可以帮助。

user3135374's answer mostly helped me get this going. user3135374的答案主要帮助我实现这一目标。

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. SDK必须是iPhone模拟器4.0,因为3.2有一个错误,使其无法正常运行单元测试。 Many people are complaining about it. 很多人都抱怨它。 I set this as the BaseSDK for my Unit Test target. 我将其设置为我的单元测试目标的BaseSDK。

  • 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 您需要将其他链接器标志“-ObjC -force_load $(PROJECT_DIR)/path/to/libOCMock.a”添加到您的单元测试目标,否则您将获得大量运行时“无法识别的选择器发送到实例”错误

  • 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 如果您想要一个具有单元测试的目标,您可以实际调试(设置断点),请遵循以下教程: 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: OCMock论坛上的这个主题有一个你可以使用的示例项目:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM