使用 XCode 4 进行单元测试时出现链接错误?
我想为我的 XCode 应用程序中的类编写一些逻辑单元测试。在 Xcode 4 中,我在 Project Navigator 中单击项目名称,然后从底部单击 Add Target。我在“Other”下选择“Cocoa Touch Unit Test Bundle”,为新目标指定“tests”的“产品名称”,然后完成。
因为我想要测试的类是作为我现有应用程序目标的一部分进行编译的,所以对于我的新“测试”目标,我立即转到“构建阶段”选项卡并将现有应用程序目标添加为唯一的目标依赖项。
然后,我转到创建的tests.m文件,导入我想要测试的类(在它的ReleasePlanManager
下面),并调用它的方法之一。但是链接器失败并出现如下错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ReleasePlanManager", referenced from:
objc-class-ref in tests.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
So the class can被发现,即使(根据我的理解)添加应用程序目标(它是其中的一部分)应该足够了?
任何帮助将不胜感激!
I want to write some logic unit tests for classes in my XCode application. In Xcode 4, I clicked on the project name in the Project Navigator, and from the bottom clicked Add Target. I chose "Cocoa Touch Unit Testing Bundle" under Other, give the new target a "product name" of "tests", and finish.
Because the class I want to test is compiled as part of my existing application target, for my new "tests" target I immediately go to the Build Phases tab and add my existing application target as the only target dependency.
I then go to the created tests.m file, import the class I want to test (below it's ReleasePlanManager
, and call one of its methods. But the linker fails with an error like:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ReleasePlanManager", referenced from:
objc-class-ref in tests.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
So the class cannot be found, even though (from my understanding) adding the application target (which it is a part of) should be sufficient?
Any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的测试包需要额外的设置:
$(BUILT_PRODUCTS_DIR)/AppName.app/AppName
(将两个位置的 AppName 替换为您的应用名称)$(BUNDLE_LOADER)
(如果您从头开始创建一个项目并启用单元测试,这些都是为您设置的。但是如果您将单元测试包添加到现有项目,但它们不是。)
Your test bundle needs extra settings:
$(BUILT_PRODUCTS_DIR)/AppName.app/AppName
(replacing AppName in both places with your app's name)$(BUNDLE_LOADER)
(If you create a project from scratch and enable unit tests, these are set up for you. But if you add a unit test bundle to an existing project, they're not.)