Xcode - 调试单元测试目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5574366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode - Debugging a unit test target
提问by aryaxt
I am writing tests for my iPhone app using OCUnit. Is there any way to debug the unit tests and have a break point to see what the heck is happening?
我正在使用 OCUnit 为我的 iPhone 应用程序编写测试。有没有办法调试单元测试并有一个断点来看看到底发生了什么?
It's ridiculously hard to write unit tests without being able to use breakpoints.
在不能够使用断点的情况下编写单元测试是非常困难的。
采纳答案by BJ Homer
The linkposted by David Gelhar is correct for Xcode 3.
David Gelhar 发布的链接适用于 Xcode 3。
For Xcode 4, things are much simpler. Edit your current scheme and go to the "Test" action. Click the '+' at the bottom and add the test bundle that contains the tests you want to run. Now when you choose Product -> Test, it will run those tests. Any active breakpoints will be hit just like you'd expect.
对于 Xcode 4,事情要简单得多。编辑您当前的方案并转到“测试”操作。单击底部的“+”并添加包含要运行的测试的测试包。现在,当您选择 Product -> Test 时,它将运行这些测试。任何活动的断点都会像您期望的那样被击中。
回答by Daniel Sproul
Using XCode 4.2, (with SenTestKit unit tests as set up by checking the "Include Unit Tests" checkbox when setting up the project), Product->Test wasn't hitting my breakpoints, but Product->Perform Action->Test Without Building seems to do the trick. Hope this helps.
使用 XCode 4.2,(通过在设置项目时选中“包含单元测试”复选框来设置 SenTestKit 单元测试),产品->测试没有达到我的断点,但产品->执行操作->测试而不构建似乎可以解决问题。希望这可以帮助。
回答by David Gelhar
Here's a blog post: Debugging Cocoa application unit testswith instructions for how to do this (for XCode 3 at least; not sure about XCode 4).
这是一篇博客文章:调试 Cocoa 应用程序单元测试以及如何执行此操作的说明(至少对于 XCode 3;不确定 XCode 4)。
回答by Matt__C
Another item to watch for in XCode 4 is that you haven't added the classes being tested to the Unit Test Target as well as the main project. It appears that it's not necessary and it will mess up your ability to have breakpoints hit.
在 XCode 4 中需要注意的另一项是您尚未将正在测试的类添加到单元测试目标以及主项目中。似乎没有必要,它会破坏您击中断点的能力。
A clue will be warning messages in the debug log when you run. The messages will look like this:
当您运行时,调试日志中的警告消息将是一个线索。消息将如下所示:
"Class XXX is implemented in both YYY and ZZZ. One of the two will be used. Which one is undefined."
“在 YYY 和 ZZZ 中都实现了 XXX 类。将使用两者之一。未定义哪一个。”
Once I removed the classes noted in the warnings from the unit test target, Xcode started hitting the breakpoints.
一旦我从单元测试目标中删除了警告中指出的类,Xcode 就开始遇到断点。
You can remove classes from a target by clicking on the .M file, and turning off its membership in the unit test target in the inspector window under "Target Membership".
您可以通过单击 .M 文件并在“目标成员身份”下的检查器窗口中关闭其在单元测试目标中的成员身份来从目标中删除类。