STAssert*() 宏内的 Xcode 补全

发布于 2024-11-26 01:55:21 字数 690 浏览 3 评论 0原文

我已经开始使用 Xcode4 的 SenTest 单元测试工具。它一直工作得很好,但是......

Xcode 没有在 STAssert*() 宏内提供代码完成建议。

我喜欢将简单的表达式直接写入断言中,以节省击键次数和屏幕空间:

STAssertTrue(mydoc.isInitialized, nil);
STAssertTrue(mydoc.pageCount == 2, nil);

我遇到的问题是,当我在断言中写入表达式时,Xcode 不提供代码完成功能。

在单元测试的上下文中,这是一个很大的遗憾,在单元测试中,代码完成可以是一种快速而方便的方法,可以提醒自己需要为其编写断言的剩余属性和方法。更不用说通常完成的好处了。

所以我开始像这样编写我的断言,这样我就可以完成代码:

BOOL b = NO;

b = mydoc.isInitialized;
STAssertTrue(b, nil);

b = mydoc.pageCount == 2;
STAssertTrue(b, nil);

我真的不想做这种事情。它更冗长,更难阅读,并且使得 Xcode 的单元测试失败消息的意义更小。

有什么想法吗?我已经删除了我的派生数据目录,重新启动了 Xcode,清理,重建等。

I've started using Xcode4's SenTest unit testing facilities. It's been working pretty well, but ...

Xcode isn't offering code completion suggestions inside STAssert*() macros.

I like to write simple expressions right into the assert, to save keystrokes and screen real estate:

STAssertTrue(mydoc.isInitialized, nil);
STAssertTrue(mydoc.pageCount == 2, nil);

The problem I'm having is that Xcode isn't offering code completion while I'm writing the expression inside the asserts.

This is a big bummer in the context of unit tests, where code completion can be a rapid and convenient way to remind yourself of the remaining properties and methods you need to write asserts for. Not to mention the usual benefits of completion.

So I've taken to writing my asserts like this, so I can get the code completion:

BOOL b = NO;

b = mydoc.isInitialized;
STAssertTrue(b, nil);

b = mydoc.pageCount == 2;
STAssertTrue(b, nil);

I'd really rather not have to do this kind of thing. It's more verbose, it's harder to read, and it makes Xcode's unit test failure messages less meaningful.

Any ideas? I've deleted my derived data dir, rebooted Xcode, cleaned, rebuilt, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

迷乱花海 2024-12-03 01:55:21

不是真正的答案,而是建议:

你说这会让你的代码更冗长、更难阅读?为什么不为您的占位符变量使用有意义的名称,这样您就可以提高测试的可读性,例如

BOOL isDocumentInitialized = mydoc.initialized;
STAssertTrue(isDocumentInitialized, @"myDoc should be initialized");

// You may even wish to change the naming convention on the object method to be
- (BOOL)isInitialized; // instead of - (BOOL)initialized;
// It is perhaps slightly clearer and follows other naming conventions 

BOOL hasTwoPages = (2 == mydoc.pageCount);
STAssertTrue(hasTwoPages, @"myDoc should have 2 pages but has %d pages", mydoc.pageCount);

Not really an answer but a suggestion:

You say it makes your code more verbose and harder to read? Why not use meaningful names for your place holder variables and you can possibly increase the readability of your tests e.g.

BOOL isDocumentInitialized = mydoc.initialized;
STAssertTrue(isDocumentInitialized, @"myDoc should be initialized");

// You may even wish to change the naming convention on the object method to be
- (BOOL)isInitialized; // instead of - (BOOL)initialized;
// It is perhaps slightly clearer and follows other naming conventions 

BOOL hasTwoPages = (2 == mydoc.pageCount);
STAssertTrue(hasTwoPages, @"myDoc should have 2 pages but has %d pages", mydoc.pageCount);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文