开发者

Linking Errors setting up GTM to do iPhone Unit Tests

My colleague and I have been struggling with unit tests now for weeks. We have tried to get SenTest, GTM, and other frameworks set up, but we can never get past a gnarly ball of linking errors.

Here's where I am now with GTM. I would appreciate any guidance.

Beyond helping out on SO, if you have experience with this, I'd happily pay a consultant. Please email me开发者_运维百科 at andrew@gaiagps.com if you think you can help me with this.

  1. I followed the instructions here: http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting. I found I also needed to add the file "GTMObjC2Runtime.h" to the project. Then, I was able to get to the point where I got the expected console output after installing the framework: "Executed 0 tests, with 0 failures (0 unexpected) in 0.030 (0.030) seconds"

  2. Next, I went to write a test case for one of my classes. I created WebAPITest.h. I created a simple test, which worked fine. I just verified 1 == 1.

  3. Next, I decided to write a test for my AppDelegate.h. So, I added #import "AppDelegate.h" to WebAPITest.h, and I got 8 linking errors. My project uses FBConnect, and the compiler complain that it can't find the FBConnect files. To address this, I added the the FBConnect header search path to the Test target's build config, and the linking errors went away.

  4. Now is where I am stumped. When I try and reference AppDelegate in the implementation, I get these linking errors:

    Building target “fooTest” of project “foo” with configuration “Debug” — (2 errors)

    Undefined symbols: ".objc_class_name_AppDelegate", referenced from: literal-pointer@__OBJC@__cls_refs@AppDelegate in WebAPITest.o ld: symbol(s) not found collect2: ld returned 1 exit status

  5. So, I tried adding AppDelegate to the Test target, but then it started wanting all the dependencies for AppDelegate too, and I'm guessing I'm not supposed to add dozens of files to the unit test target.

Any idea what I need to do next?


Your test bundle does need access to the compiled class you are trying to test. It's your decision to accomplish that by either adding it directly to the target (and yes, with all its dependencies), by linking to a library that implements the class, or by setting up your test bundle so that it is loaded by a host application that has an implementation of the class.

This reference might be useful to you:

http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html#//apple_ref/doc/uid/TP40007959-CH20-SW3

And also from the main unit testing documentation at Apple:

http://developer.apple.com/mac/library/DOCUMENTATION/DeveloperTools/Conceptual/UnitTesting/1-Articles/CreatingTests.html#//apple_ref/doc/uid/TP40002171

Look for terms like "Test Host" and "Bundle Loader."

This stuff is not very straightforward to understand but the documentation eventually clarifies everything if you hunker down and plow through it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜