使用 XCode 4 进行单元测试的链接错误? [英] Linking error for unit testing with XCode 4?

查看:21
本文介绍了使用 XCode 4 进行单元测试的链接错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 XCode 应用程序中的类编写一些逻辑单元测试.在 Xcode 4 中,我在 Project Navigator 中单击项目名称,然后从底部单击 Add Target.我在Other下选择了Cocoa Touch Unit Testing Bundle",给新目标一个tests"的product name",然后完成.

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.

然后我转到创建的 tests.m 文件,导入我要测试的类(在它下面是 ReleasePlanManager,然后调用其中一个方法.但是链接器失败并出现如下错误:

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!

推荐答案

你的测试包需要额外的设置:

Your test bundle needs extra settings:

  • Bundle Loader 设置为 $(BUILT_PRODUCTS_DIR)/AppName.app/AppName(将两个地方的 AppName 替换为您的应用名称)
  • 测试主机设置为$(BUNDLE_LOADER)
  • Set Bundle Loader to $(BUILT_PRODUCTS_DIR)/AppName.app/AppName (replacing AppName in both places with your app's name)
  • Set Test Host to $(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.)

这篇关于使用 XCode 4 进行单元测试的链接错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆