有什么方法可以在 SenTest 中运行代码仅成功吗?

发布于 2024-12-29 12:15:53 字数 99 浏览 5 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帥小哥 2025-01-05 12:15:53

你的问题引起了我的好奇,所以我就来研究一下!

我想我会重写类 SenTestCase 中的 failWithException: 方法(你的测试运行的类继承于此),并设置一个“保留输出文件”标志或其他东西在调用 super 的方法之前。

以下是 SenTestCase.h 关于该方法的说明:

/*"Failing a test, used by all macros"*/
- (void) failWithException:(NSException *) anException;

因此,如果您仅使用 SenTest 宏来测试和/或失败(并且您的情况很可能是这样),那么这应该涵盖任何测试失败。

Your question made me curious so I looked into it!

I guess I would override the failWithException: method in the class SenTestCase (the class your tests run in inherits from this), and set a "keep output files" flag or something before calling the super's method.

Here's what SenTestCase.h says about that method:

/*"Failing a test, used by all macros"*/
- (void) failWithException:(NSException *) anException;

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.

待天淡蓝洁白时 2025-01-05 12:15:53

我从未深入研究过这方面的脚本,但似乎您可以自定义如何调用实际运行测试的脚本来执行此操作。在 Xcode 4 中,查看测试目标的“构建阶段”选项卡中的最后一步。我的包含这个:

# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"

我还没有仔细研究这个脚本的内容或它在我的机器上引入的许多下标,但大概它们调用了 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:

# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文