导入的文件无法在OCUnit中识别

mag*_*725 5 iphone xcode linker unit-testing ocunit

我正在使用XCode 3.2.3和iOS 4.0上的OCUnit在我的iPhone应用程序上进行单元测试.我已成功设置我的测试环境以适当地传递和失败基本测试,但是当我导入自己的文件时(在这种情况下,"UserAccount.h",它无法编译并告诉我:

"_OBJC_CLASS _ $ _ UserAccount",引自:

然后它说"未找到符号".这让我感到某种链接器错误,但我不知道发生了什么.我已多次建造和清理所有目标,但无济于事.这是我的测试代码:

#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
Run Code Online (Sandbox Code Playgroud)

任何建议将不胜感激.谢谢!

-Matt

Tec*_*Zen 2

我猜想 UserAccount.m 尚未添加到测试目标中。这将导致“找不到符号”错误。我见过很多次,即使实现文件不是目标的一部分,Xcode 也能识别多个目标的标头。

如果这不起作用,请尝试使用 清空 Xcode 缓存Xcode>Empty Caches...