查看 XCTest 和 Xcode 5 单元测试,但没有看到如何在 Xcode 5 中的 Instruments 下运行我的单元测试...

具体来说,我想在测试期间查找泄漏(在这种情况下不必自动化,尽管这显然很有用)。

可能的?

有帮助吗?

解决方案

我认为这是最简单的方法:

  1. 在测试中的某个位置设置一个断点(我一直在设置方法中执行它)
  2. 在仪器中打开一个新文件
  3. 运行应用程序并确保它在断点
  4. 停止
  5. 从目标下拉仪器中的仪器选择附加到流程并滚动到您的进程
  6. 单击Record,然后在Xcode中恢复

其他提示

在Xcode中,右键单击测试导航器中的测试,然后选择“配置文件”testName“”:

以下是在 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 在终端中) - 您需要启用“Traverse Packages”才能在 Xcode 应用程序内导航。

5) 将步骤 1 中显示的“.xctest”产品从 Finder 拖放到“参数”字段中 - 这将输入其绝对路径。

6) 单击“选择”。

您现在已准备好从 Instruments 运行单元测试!

enter image description here

I created a new target based on the mac app target I am testing, then added the xctest classes to the files to compile.

I then added the /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework to the frameworks to link against.

Then added its path $(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks to the Runpath Search Paths.

Then in the main.m I added the following:

    XCTestSuite *suite = [XCTestSuite testSuiteWithName:@"My tests"];
    [suite addTest:[VideohogCachingTest testCaseWithSelector:@selector(testCompleteSequentialText)]];
    [suite run];

This ran the test testCompleteSequentialText on the class VideohogCachingTest I needed to run as a normal application, therefore allowing me to run the test by either command+R or in this case, profiling with command+I. I could then catch a zombie and trace the problem, which was not a possibility for me previously. If you'd like to run all your tests you can do:

XCTestSuite *suite = [XCTestSuite defaultTestSuite];
[suite run];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top