Xcode 6测试目标问题 [英] Xcode 6 Testing Target Troubles

查看:63
本文介绍了Xcode 6测试目标问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里经历了很多问题和答案,最终陷入了困境.

I've been going through many questions and answers here, and have ended up in a quandary.

现在,我对项目代码的状态感到满意,因此我想实现单元测试.因此,我添加了一个测试目标,可以使其正确编译吗?不....我确定这很简单,但我无法解决.

Now that I'm happy with the state of my project code, I wanted to implement unit testing. So I added a testing target, can I get it to compile correctly? No.... I'm sure it's something simple, but I cannot work it out.

该项目包含2个第三方私有框架.

The project contains 2 3rd party private frameworks.

我的测试目标包加载程序参数设置为:

My test target bundle loader parameter is set to:

$(TEST_HOST)

我的测试目标测试主机参数设置为:

My test target test host parameter is set to:

$(BUILT_PRODUCTS_DIR)/My App.app/Contents/MacOS/My App

当我尝试编译时,出现如下错误:

When I try to compile, I get errors like this:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_MyArrayController", referenced from:
      objc-class-ref in SMyAppLogicTests.o

我查了一下,并在以下位置找到了类似的答案: XCTestCase:ld:在架构x86_64中找不到符号

I look this up, and find answers like this on: XCTestCase: ld: symbol(s) not found for architecture x86_64

基本上是说我需要将类添加到测试目标中.这似乎击败了在工作应用程序之上构建点的能力,但是嘿.因此,我将所有.m文件添加到测试目标中,并进行编译!万岁,但是,我遇到了新问题:

Basically saying I need to add my classes to my test target. This seems to kind of defeat the point building on top of the working app, but what the hey. So I add all .m files to the test target, and it compiles! Hooray, but, I have new problems:

Class MyClass is implemented in both /Users/georgebrown/Library/Developer/Xcode/DerivedData/My_App-akedavtbgqpujscilxqmhsvikcku/Build/Products/Debug/My App.app/Contents/MacOS/My App and /Users/georgebrown/Library/Developer/Xcode/DerivedData/My_App-akedavtbgqpujscilxqmhsvikcku/Build/Products/Debug/My App Tests.xctest/Contents/MacOS/My App Tests. One of the two will be used. Which one is undefined.

那是有道理的,如果我的应用程序中已经包含m个文件,为什么还要放入它们.因此,我进行了查找,并得到了一个答案,使我回到了第一位:

That makes sense, why do I have to put the m files in if they're already contained in my app. So I look it up, and get an answer that puts me back in the first position:

Class Foo在MyApp和MyAppTestCase中都实现.将使用两者之一.哪个未定义

我想念什么?我被困了一个星期,只是试图在Xcode中实施测试(更不用说Xcode服务器对我的服务器做了什么,我仍然必须弄清楚这一点),当时我计划3-4天的时间来愚蠢地思考编写测试这将是一个快速的设置.

What am I missing? I've been stuck for a week just trying to implement testing in Xcode (Not to mention what Xcode server did to my server, I still have to figure that out), when I planned a 3-4 days for writing the tests foolishly thinking it would be a quick setup.

我删除了测试目标,然后重新开始.第一件事行不通的是,它找不到我的第三部分私有框架.因此,我在框架搜索路径中添加了$(PROJECT_DIR).

I deleted my test target and started again. First thing that didn't work is that it couldn't find my 3rd part private frameworks. So I added $(PROJECT_DIR) to the frameworks search paths.

接下来,我再次为我的班级得到了体系结构的未定义符号错误.我注意到我的Bundle Loader未设置,所以我将其设置为$(TEST_HOST),现在可以运行测试了!万岁.

Next, I started getting the Undefined Symbols for architecture error again for my classes. I noticed my Bundle Loader was unset, so I set that to be $(TEST_HOST), now the tests run! Hooray.

现在,我无法为运行操作"构建,但可以为测试"构建.....我猜是进步.我再次获得架构x86_64的未定义符号:错误.

Now I can't build for the Run Action, but build for Test works..... Progress I guess. I get the Undefined symbols for architecture x86_64: error again.

我已通过编辑方案并为构建中的测试目标取消选择运行"来解决此问题.我不确定我是否完全了解该方案的工作原理,但是确实成功了.

I've managed to fix that by editing the scheme, and deselecting "Run" for the test target on the build. I'm not sure I entirely understand how the scheme is supposed to work, however, it did the trick.

推荐答案

XCTesting东西通过在运行时将测试包注入应用程序来工作.当您添加一个新的测试目标时,Xcode会为您设置所有东西:我建议如果您有一个让您感到悲伤的测试目标,请在Xcode中创建一个新目标并将您的测试用例转移到该目标上.目标. 然后,您只需遵循三个规则:

The XCTesting thingie works by injecting the test bundle into the app at runtime. When you add a new test target, Xcode takes care of setting up all that stuff for you: I'd suggest if you have a test target that is giving you grief, you create a new one in Xcode and transfer your test cases to that target. Then you only have to follow three rules:

  1. 仅将类实现文件添加到应用程序目标,而不能添加到 测试任何测试目标.这将防止在MyApp和MyAppTestCase中都实现了类Foo.将使用两者之一.未定义的那一个"警告
  2. 仅添加XCTestCase文件进行测试 目标.
  3. #import"用于测试用例的每个自定义类的头文件.
  1. Add your class implementation files only to app targets, never to test any test targets. This will prevent the "Class Foo is implemented in both MyApp and MyAppTestCase. One of the two will be used. Which one is undefined" warning
  2. Add your XCTestCase files only to test targets.
  3. '#import' the header files of each custom class that you use in a test case.

这篇关于Xcode 6测试目标问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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