objective-cunit-testingiphone-sdk-4.1

Unit Testing in iphone i got below error


whenever i run the unit testing application to find whether appdelegate is there r not using the test suit

-(void)testAppDelegate
{
id app_delegate=[[UIApplication sharedApplication]delegate];
STAssertNotNil(app_delegate,@"delegate not found");
}

i got this error. Please help.

"_OBJC_CLASS_$_UIApplication", referenced from:

  objc-class-ref-to-UIApplication in Tests.o

ld: symbol(s) not found

collect2: ld returned 1 exit status


Solution

  • I believe this is a linker error and not a runtime error. You need to link the same frameworks that you use in your iPhone build target to your unit test target. Particularly this error indicates that the UIKit framework is not linked to your unit test target. (To be safe link UIKit, Foundation and CoreGraphics as well to your target).

    You can do this, by expanding the Targets node in XCode, get info on your unit test target, and under the General tab, in the Linked Libraries you need to add these 3 frameworks ;)

    Hope this helps, Moszi