views:

32

answers:

2

Hi,

I am doing unit testing on my iPhone app using OCUnit on XCode 3.2.3, and iOS 4.0. I have successfully set up my testing environment to pass and fail basic tests appropriately, but when I import my own files (in this case, "UserAccount.h", it fails to compile and tells me:

"_OBJC_CLASS_$_UserAccount", referenced from:

It then says "Symbol(s) not found". This strikes me as some sort of linker error, but I have no idea what's going on. I have built and cleaned all targets numerous times, but to no avail. Here is my testing code:

#import "SomeTestCase.h"
#import "UserAccount.h"

@implementation SomeTestCase

 - (void)testUserAccount
 {
 // UserAccount.m //

 UserAccount *testAccount = [[UserAccount alloc] initWithUsername:@"" password:@"" deviceToken:@""];
 [testAccount registerNew];
 NSLog(@"USERID = %@", testAccount.userID);
 STAssertEquals([testAccount login], NO, @"Failure: Login should fail with blank username and password."); // should fail with no username or password

 UserAccount *testAccount2 = [[UserAccount alloc] initWithUsername:@"user" password:@"" deviceToken:@""]; 
 STAssertEquals([testAccount2 login], NO, @"Failure: Login should fail with blank password.");// should fail with no password

 UserAccount *testAccount3 = [[UserAccount alloc] initWithUsername:@"" password:@"pass" deviceToken:@""]; 
 STAssertEquals([testAccount3 login], NO, @"Failure: Login should fail with blank username.");// should fail with no password

 }

@end

Any advice would be greatly appreciated. Thanks!

-Matt

+2  A: 

I would guess that UserAccount.m has not been added to the testing target. That will cause the "Symbols not found" error. I seen times with multiple targets in which Xcode recognizes headers even though the implementation file is not part of target.

If that doesn't work, try emptying the Xcode cache with Xcode>Empty Caches....

TechZen
Thank you! Adding the source to the target did the trick.
mag725
A: 

One question, I have a project with thousand of files. When i create the UnitTest Target and the Class with test methods, if i use ClassA i must to set ClassA.m part of the UnitTest Target. ClassA uses ClassB... so ClassB also must to be part of UnitTest Target because "_OBJC_CLASS_$_ClassB, referenced from" error appears.

The problem is that i use thousand of files that use other files... and i can't set for each one to be part of UnitTest target.

How can i solve it?? Thank you!!!

Fernando