GH-Unit for unit testing Objective-C code, why am I getting linking errors?

你说的曾经没有我的故事 提交于 2019-12-01 18:18:16

If the target you are testing is an application, you'll need to manually include the Show.h/m files in both your main target and your test target.

I also updated the README to reflect this:

  • If your main target is a library: Add a linked library, and select your main target; This is so you can link your test target against your main target, and then you don't have to manually include source files in both targets.
  • If your main target is an application, you will need to include these source files in the Test project manually.

Sorry for the confusion! Having to include files in both targets is not ideal.

You have to have an @implementation for Show.

Or you could use

Show* s = [[objc_getClass("Show") alloc] init];
...

or

Show* s = [[NSClassFromString(@"Show") alloc] init];
...

to resolving the class in run-time.

Somehow Apple's example works without duplicating the .m files in the target.

Download Apple's unit testing sample code (iPhoneUnitTests.zip) here:

http://developer.apple.com/IPhone/library/samplecode/iPhoneUnitTests/Introduction/Intro.html

Click on the CalcTests target. Only CalcTests.m is in this target.

Build the target. It builds without any link errors for CalcAppDelegate or other classes.

What's the magic that makes this work?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!