_OBJC_CLASS_ $ Errors when testing individual models in iOS 4.2

Well, I spent about 5 hours trying to figure it out. Absolutely none of the past resolutions on Stackoverflow topics worked for me, so I hope someone can give me an answer, rather than a wild goose hunt.

Problem: I have an x-code project that requires unit testing of my custom classes. I am using X-Code 3.2.5 with iOS SDK 4.2. After several different ways, I cannot do my unit testing on custom classes. It works great with Apple examples.

Custom classes are simple subclassed NSObjects with trivial iVars. We will call the class "Snookie".

I have already tried several dubious resolutions, but would like to get an answer from someone who had the same problem, with an answer that makes sense.

Replication:

  • Add MyAppTesting unit test object.
  • In the "MyAppTesting Information" section, add MyApp as a direct dependency.
  • Create a group called Tests.
  • In the Tests section, add the CaseiveC Test Case class.
  • In the new test case .h class, import Snookie.h and create iVar:
#import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> #import "Snookie.h" @interface SnookieTests : SenTestCase { Snookie *snookieObject; } @end 

In the new test case, the class .m, alloc / init snookie looks like this:

 #import "SnookieTests.h" @implementation SnookieTests - (void) setUp { snookieObject = [[Snookie alloc] init]; } - (void) tearDown { [snookieObject release]; } @end 

Error:

 "_OBJC_CLASS_$_Snookie", referenced from: Objc-class-ref-to-Snookie in SnookieTests.o Symbol(s) not found Collect2: Id returned 1 exit status 
+4
source share
3 answers

What the linker thinks is trying to tell you that it cannot find @implementation for the Snookie class in MyAppTesting or any of its related frameworks / libraries.

Adding MyApp as a direct dependency is not enough to tell Xcode to compile / link code with MyApp . You need to explicitly add the Snookie.m file to your target for MyAppTesting .

+4
source

Adding .m files to the application directly to the test target solves the problem, it is redundant and not needed. Follow the steps described here with two bits of Lab to get it working. To summarize, make sure your ...

  • test target Bundle Loader build configuration points to your application package.
  • test target Test Host assembly setup points to your application package.
  • Symbols Hidden by Default : NO .
+4
source

kperryua is correct.

In Xcode 5, click on the implementation file that will be checked for compliance with the class (for example, XYZCustomClass.m), make sure that you see the Utilities screen (which can be displayed in the menu "View"> "Utilities"> "Show Utilities" if it hidden), and then select the [your tests name] Tests check box in the Target Membership field. Voila, your block is testing "OBJC_CLASS_ $ ...", which is referenced by: objc-class-ref in., ._ Tests.o "will disappear.

0
source

All Articles