gpt4 book ai didi

iphone - OCUnit 无法识别导入的文件

转载 作者:行者123 更新时间:2023-12-03 18:58:07 25 4
gpt4 key购买 nike

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

“_OBJC_CLASS_$_UserAccount”,引用自:

然后显示“未找到符号”。这让我觉得是某种链接器错误,但我不知道发生了什么。我已经多次 build 并清理了所有目标,但毫无效果。这是我的测试代码:

#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

如有任何建议,我们将不胜感激。谢谢!

-马特

最佳答案

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

  1. 您的项目(左上角)-> 目标 -> 您的测试目标 -> 目标依赖项 -> + 您的主应用目标
  2. 切换到“build设置”选项卡 -> 链接 -> 捆绑加载程序 -> $(BUILT_PRODUCTS_DIR)/YourAppName.app/YourAppName

了解如何正确完成此操作的一个好方法是创建一个带有单元测试的全新 XCode 4 项目,然后查看如何设置测试目标。您会注意到应用程序 .m 文件未包含在测试目标中。

关于iphone - OCUnit 无法识别导入的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com