有什么方法可以在 SenTest 中运行代码仅成功吗?
在我的 Mac Cocoa 单元测试中,我想输出一些文件作为测试过程的一部分,并在测试完成时删除它们,但只有在没有失败时。如何做到这一点(和/或最干净的方法是什么)?
In my Mac Cocoa unit tests, I would like to output some files as part of the testing process, and delete them when the test is done, but only when there are no failures. How can this be done (and/or what's the cleanest way to do so)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题引起了我的好奇,所以我就来研究一下!
我想我会重写类
SenTestCase
中的failWithException:
方法(你的测试运行的类继承于此),并设置一个“保留输出文件”标志或其他东西在调用super
的方法之前。以下是 SenTestCase.h 关于该方法的说明:
因此,如果您仅使用 SenTest 宏来测试和/或失败(并且您的情况很可能是这样),那么这应该涵盖任何测试失败。
Your question made me curious so I looked into it!
I guess I would override the
failWithException:
method in the classSenTestCase
(the class your tests run in inherits from this), and set a "keep output files" flag or something before calling thesuper
's method.Here's what SenTestCase.h says about that method:
So, provided you only use the SenTest macros to test and/or fail (and chances are this is true in your case), that should cover any test failure.
我从未深入研究过这方面的脚本,但似乎您可以自定义如何调用实际运行测试的脚本来执行此操作。在 Xcode 4 中,查看测试目标的“构建阶段”选项卡中的最后一步。我的包含这个:
我还没有仔细研究这个脚本的内容或它在我的机器上引入的许多下标,但大概它们调用了 otest 或其他一些测试设备可执行文件,并且测试结果将返回到该脚本。熟悉这些脚本一段时间后,您可能会找到一种简单的方法来根据测试结果有条件地删除输出文件。
I've never dug into the scripts for this, but it seems like you could customize how you call the script that actually runs your tests to do this. In Xcode 4, look at the last step in the Build Phases tab of your test target. Mine contains this:
I haven't pored through the contents of this script or the many subscripts it pulls in on my machine, but presumably they call otest or some other test rig executable and the test results would be returned to that script. After a little time familiarizing yourself with those scripts you would likely be able to find a straightforward way to conditionally remove the output files based on the test results.