使用 XCode 4 进行单元测试时出现链接错误?

发布于 2024-11-17 01:38:15 字数 676 浏览 1 评论 0原文

我想为我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笏见 2024-11-24 01:38:15

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

  • Bundle Loader 设置为 $(BUILT_PRODUCTS_DIR)/AppName.app/AppName (将两个位置的 AppName 替换为您的应用名称)
  • 设置 测试主机$(BUNDLE_LOADER)

(如果您从头开始创建一个项目并启用单元测试,这些都是为您设置的。但是如果您将单元测试包添加到现有项目,但它们不是。)

Your test bundle needs extra settings:

  • 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文