我是否需要做一些事情才能使 OCunit 测试能够使用 XCode 4 进行开箱即用的编译?
我今天刚刚安装了 XCode 4(使用 Apple mac 应用商店),创建了一个新的 Mac OS 应用程序,并尝试切换到测试模式,并构建它为我生成的测试框架代码。它在这里失败:
在 mytests.h 中:
#import <SenTestingKit/SenTestingKit.h>
错误是:
file://..mytests.h:错误:词法或预处理器问题:找不到“SenTestingKit/SenTestingKit.h”文件
现在,当我使用从终端定位来查找 SenTestingKit.h,我注意到它存在于 /Developer-old/Library/Frameworks 文件夹下(这是 XCode 4 安装程序将我的 /Developer 文件夹重命名为的文件夹)。没有新的/Developer/Library/Frameworks。除了开发人员旧版本之外,我似乎在磁盘上找不到 SenTestingKit.framework。
这是怎么回事?似乎 SenTestingKit.framework 未随 XCode 4 一起提供。
更新:
此外,当我将旧的 SenTestingKit 框架从 XCode 3 复制到 /Developer/Library/Frameworks 时,它可以构建,但它无法按照我期望的方式工作。虚拟测试被设计为失败,但是当我“运行测试”时,我只是得到正常的可可应用程序文档窗口打开,并且没有迹象表明我的测试失败了(正如我想要的那样)。
这很糟糕。我无法让单元测试失败。这对我来说不是平常的情况,你明白。
I just installed XCode 4 today (using Apple mac app store), and I created a new Mac OS application, and tried to switch to test mode,and build the test skeleton code it generated for me. It failed here:
In mytests.h:
#import <SenTestingKit/SenTestingKit.h>
The error is:
file://..mytests.h: error: Lexical or Preprocessor Issue: 'SenTestingKit/SenTestingKit.h' file not found
Now, when I use locate from the terminal to find SenTestingKit.h, I notice it exists under the /Developer-old/Library/Frameworks folder (which is what XCode 4 installer renamed my /Developer folder to). There is no new /Developer/Library/Frameworks. And I can't seem to find SenTestingKit.framework on my disk, other than the developer-old one.
What's up? It seems SenTestingKit.framework is not shipped with XCode 4.
Update:
Furthermore, When I copy my old SenTestingKit framework from XCode 3 into /Developer/Library/Frameworks, it sort of builds, but it doesn't work the way I would expect. The dummy test is designed to just fail, but when I "run test", I just get the normal cocoa app document window opening, and no indication that my test has failed (as I intend it to do).
This is pretty bad. I can't get a Unit test to FAIL. That's not the usual situation for me, you understand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能会发现这是因为您已将 Xcode 4 安装到 /Xcode 4.x/ 或类似目录中。空格导致了问题,因为 -I 路径是“Xcode”和“4.x/Library/Frameworks”。
要解决此问题,您需要做的是选择测试目标,然后在其构建设置下找到框架搜索路径,并在两个参数两边加上引号,这样您就有:
“$(SDKROOT)/Developer/Library/ Frameworks”和“$(DEVELOPER_LIBRARY_DIR)/Frameworks”
然后您的默认测试将编译、链接并失败。
You may find that the reason for this is because you've installed Xcode 4 into a directory such as /Xcode 4.x/ or similar. The space is causing the problem because the -I paths are "Xcode" and "4.x/Library/Frameworks".
To fix this, what you need to do is select your test target, and under its build settings go and find the Framework Search Path, and put quotes around the two arguments, so you have:
"$(SDKROOT)/Developer/Library/Frameworks" and "$(DEVELOPER_LIBRARY_DIR)/Frameworks"
Then you default tests will compile, link and fail.
您可能需要将框架导入到您的项目中。否则头文件将无法被识别。
如果您看不到您正在寻找的框架,您可以在项目的构建设置中调整框架查找路径。
You will maybe need to import the framework into your project. Otherwise, the header file won't be recognize.
If you can't see the framework you're looking for, you can adjust the framework look paths in your project's build settings.
当您在与主代码相同的项目中构建单元测试时,请确保 XCode 4 不会自动将您的 mytests.m 文件连接到主代码的“编译源”部分。
例如,如果您的项目中有两个目标:
MyProject
MyProjectTests
检查 MyProject 的构建阶段,看看 XCode 是否将 mytests.m 添加到“编译源”折叠面板中。这将导致您的构建失败,因为 SenTest 未包含在主项目中。
When you're building unit tests in the same project as you main code, make sure that XCode 4 didn't automatically connect you mytests.m file into the "Compile Sources" section of your main code.
For example, if you have two targets in our project:
MyProject
MyProjectTests
Check the Build Phases for MyProject to see if XCode added mytests.m into the "Compile Sources" accordion. This will cause your builds to fail because SenTest isn't included in the main project.