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

Iphone OCUnit中无法识别导入的文件,iphone,unit-testing,xcode,linker,ocunit,Iphone,Unit Testing,Xcode,Linker,Ocunit,我正在使用XCode 3.2.3和iOS 4.0上的OCUnit对我的iPhone应用程序进行单元测试。我已经成功地设置了我的测试环境,以适当地通过和失败基本测试,但当我导入自己的文件(在本例中为“UserAccount.h”)时,它无法编译并告诉我: “\u OBJC\u CLASS\u$\u UserAccount”,引用自: 然后它会说“找不到符号”。这让我觉得是某种链接器错误,但我不知道发生了什么。我已经构建并清理了无数次所有目标,但都无济于事。以下是我的测试代码: #import "S

我正在使用XCode 3.2.3和iOS 4.0上的OCUnit对我的iPhone应用程序进行单元测试。我已经成功地设置了我的测试环境,以适当地通过和失败基本测试,但当我导入自己的文件(在本例中为“UserAccount.h”)时,它无法编译并告诉我:

“\u OBJC\u CLASS\u$\u 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
如有任何建议,将不胜感激。 谢谢


-Matt

我猜UserAccount.m没有添加到测试目标中。这将导致“Symbols not found”(未找到符号)错误。我曾见过多个目标中Xcode识别头,即使实现文件不是目标的一部分


如果这不起作用,请尝试在Xcode 4中使用
Xcode>空缓存清空Xcode缓存…

至少您不应该测试目标中包含应用程序.m文件。正确的方法是:

  • 您的项目(左上)->目标->您的测试目标->目标相关性->+您的主要应用程序目标
  • 切换到构建设置选项卡->链接->捆绑加载程序->$(构建产品目录)/YourAppName.app/YourAppName
  • 了解如何正确完成这项工作的一个好方法是创建一个全新的带有单元测试的XCode 4项目,然后查看如何设置测试目标。您会注意到,测试目标中不包含application.m文件