查看 XCTest 和 Xcode 5 单元测试,却没有看到如何在 Xcode 5 中的 Instruments 下运行我的单元测试...
具体来说,我想在测试期间寻找泄漏(在这种情况下,这不必自动化,但显然这很有用)。
可能的?
查看 XCTest 和 Xcode 5 单元测试,却没有看到如何在 Xcode 5 中的 Instruments 下运行我的单元测试...
具体来说,我想在测试期间寻找泄漏(在这种情况下,这不必自动化,但显然这很有用)。
可能的?
我认为这是最简单的方法:
这是在 Xcode 6 下的正确方法:
1) 在您的 Xcode 项目中,显示“Products”文件夹,选择“.xctest”产品,右键单击,最后在上下文菜单中选择“Reveal in Finder”。
2) 启动 Instruments 并使用您选择的模板创建一个新文档。
3)对文档执行“选择目标...”
4) 导航并选择 Xcode 用于运行测试的工具/Applications/Xcode.app/Contents/Developer/usr/bin/xctest
(您可以xcrun -f xctest
在终端中找到此位置) - 您需要启用“遍历包”才能在 Xcode 应用程序中导航。
5) 将步骤 1 中显示的“.xctest”产品从 Finder 拖放到“参数”字段中 - 这将输入其绝对路径。
6) 点击“选择”。
您现在已准备好从 Instruments 运行单元测试!
我基于我正在测试的 mac app 目标创建了一个新目标,然后将 xctest 类添加到要编译的文件中。
然后,我将/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework添加到要链接的框架中。
然后将其路径$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks 添加到Runpath Search Paths。
然后在 main.m 我添加了以下内容:
XCTestSuite *suite = [XCTestSuite testSuiteWithName:@"My tests"];
[suite addTest:[VideohogCachingTest testCaseWithSelector:@selector(testCompleteSequentialText)]];
[suite run];
这在我需要作为普通应用程序运行的类VideohogCachingTest上运行测试testCompleteSequentialText,因此允许我通过 command+R 或在本例中使用 command+I 进行分析来运行测试。然后我可以抓住一个僵尸并追踪问题,这对我来说以前是不可能的。如果您想运行所有测试,您可以执行以下操作:
XCTestSuite *suite = [XCTestSuite defaultTestSuite];
[suite run];
Profile
提示Instruments
喜欢Activity Monitor
, Allocations
, Time Profiler
...
有几个注意事项:
应用
单元测试包
UI 测试包