Alright, I've spent about 5 hours trying to figure this out. Absolutely none of the past Stackoverflow topics resolutions worked for me, so I'm hoping someone can give me an answer and not a wild goose-chase.
Problem: I have an x-code project that needs unit-testing of my custom classes. I'm using X-Code 3.2.5 with iOS SDK 4.2. After following several different ways, I cannot get my unit-testing working on custom classes. It works fine using Apple's examples.
The custom classes are simple sub-classed NSObjects with trivial iVars. We'll call the class "Snookie".
I've already attempted several questionable resolutions, but would like a response from someone who has had the exact same issue, with an answer that makes sense.
Replication:
#import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> #import "Snookie.h" @interface SnookieTests : SenTestCase { Snookie *snookieObject; } @end
In the new test case class .m, alloc/init snookie as follows:
#import "SnookieTests.h" @implementation SnookieTests - (void) setUp { snookieObject = [[Snookie alloc] init]; } - (void) tearDown { [snookieObject release]; } @end
The error:
"_OBJC_CLASS_$_Snookie", referenced from:
Objc-class-ref-to-Snookie in SnookieTests.o
Symbol(s) not found
Collect2: Id returned 1 exit status
What think linker is trying to tell you is that it cannot find an @implementation
for the Snookie
class in MyAppTesting
or any of the frameworks/libraries it links.
Adding MyApp
as a directly dependency is not sufficient to tell Xcode to compile/link the code from MyApp
. You need to explicitly add the Snookie.m
file to your target for MyAppTesting
.
While adding your app's .m files directly to your testing target solves the problem, it's redundant and unnecessary. Follow the steps outlined here by Two Bit Labs to get it working. To sum up, make sure your…
Bundle Loader
build setting is pointing at your app's bundle.Test Host
build setting is pointing at your app's bundle.Symbols Hidden by Default
build setting is NO
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With