你如何测试你的 Cocoa GUI?

发布于 2024-07-14 00:55:45 字数 279 浏览 8 评论 0 原文

我想为我的 Cocoa 程序的 GUI 编写一些测试。

有没有好的 Cocoa 应用程序 GUI 测试框架? 我唯一发现的是 Squish ,2.400 欧元,远远超出了我的预算……

有什么想法吗? 如何测试您的 Cocoa GUI?

I would like to write some tests for the GUI of my Cocoa program.

Is there any good GUI testing framework for Cocoa apps? The only thing I found is Squish, which, at 2.400€, is well beyond my budget…

Any ideas? How do you test your Cocoa GUIs?

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

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

发布评论

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

评论(5

掌心的温暖 2024-07-21 00:55:45

这取决于“测试 Cocoa GUI”的含义。

如果您想要旧的工具 虚拟用户 工具,那么这些就很少了。 相距甚远; 您将看到 Squish 和 Eggplant 等工具。

如果您想为应用程序的人机界面编写单元测试,我建议您遵循“信任,但验证”方法,只要您建立正确的连接(根据您的框架),您就会相信。用户可以与您的框架正确交互。 这意味着您可以通过验证您的模型和控制器代码是否正确连接到您的视图来完成大部分测试。

在我的博客上,我写了几个示例来具体说明如何使用 Cocoa 执行此操作,其中一个用于 测试使用 target-action 构建的用户界面,以及一个用于 测试使用 Cocoa 绑定构建的用户界面。 (当然,请记住,这两种技术并不排斥:如果您想在通过 Cocoa 绑定管理的表视图中进行拖放操作,您还需要一个数据源,并且可能还有一个通过目标连接的委托 -动作。)

我通常不编写单元测试的目的是控件在其超级视图中的定位或类型。 然而,有时候,获得并保持正确这一点很重要; 在这种情况下,我只需查询控件的适当属性并使用标准断言来验证它们。

几乎从不做的是编写代码来“模拟事件”。 我最接近的方法是构造一个假的拖动信息对象并将其传递给大纲视图数据源,以确保它将正确处理拖动。

It depends on what you mean by "testing Cocoa GUIs."

If you want tools like the old Virtual User tool included with MPW, then those are few & far between; you'll be looking at tools like Squish and Eggplant.

If you want to write unit tests for your application's human interface, I suggest you follow a "trust, but verify" approach where you trust that as long as you're making the right connections (according to your framework) that your user can interact properly with your framework. That means you can do the majority of your testing by verifying your model and controller code are hooked up to your views correctly.

On my weblog, I've written a couple of examples of how to do this specifically with Cocoa, one for testing user interfaces built with target-action, and one for testing user interfaces built with Cocoa bindings. (Remember, of course, that the two technologies aren't exclusive: If you want to do drag & drop in a table view managed via Cocoa bindings, you'd also have a data source and probably a delegate hooked up via target-action.)

The thing I don't write unit tests for — generally — is the positioning or type of controls in their superview. Sometimes that is important to get and keep correct, however; in that case, I can just query the appropriate properties of the controls and verify them using the standard assertions.

What I virtually never do is write code to "simulate events." The closest I've ever come to that is constructing a fake drag info object and passing that to an outline view data source to ensure it will deal with drags correctly.

往事随风而去 2024-07-21 00:55:45

我建议您看一下 Google 的 Macintosh 工具箱。 除了其他一些不错的东西之外,它还为 NSView 和 CALayers 添加了一组非常好的状态和渲染测试。 在单元测试中,您断言视图/图层状态或渲染图像与保存的(按名称)模板匹配。 如果测试包中不存在模板或与保存的版本不匹配,则会生成新的编码状态或渲染的 TIFF 以供审核。 GTM 为 NSView 和 CALayer 提供了类别来进行状态编码和渲染。 显然,您可以在自己的 NSView 或 CALayer 子类上覆盖这些类别,以编码相关状态(使用 NSCoder 协议)或渲染。

它还允许您(轻松)以编程方式发送关键事件并通过单元测试运行运行循环,并且它支持 OS X 和 iPhone 上的单元测试。

I would suggest you take a look at Google's Toolbox for Macintosh. It has, among some other nice goodies, a very nice set of state and rendering test additions for NSView and CALayers. In your unit tests you assert that the view/layer state or rendered image matches a saved (by name) template. If the template doesn't exist in the test bundle or doesn't match the saved version, a new encoded state or rendered TIFF is produced for review. GTM provides categories for NSView and CALayer to do state encoding and rendering. Obviously you can override these categories on your own NSView or CALayer subclasses to encode relevant state (using the NSCoder protocol) or rendering.

It also allows you to (easily) programatically send key events and run the run loop from with unit tests and it supports unit testing on both OS X and iPhone.

苏大泽ㄣ 2024-07-21 00:55:45

我创建了一个开源 Python 包,它使用 Apple Accessibility API 等来创建经典的 GUI 自动化库,让您能够了解 Cocoa GUI 并与之交互。 PyATOM 主页

I created an open source Python package that uses the Apple Accessibility API among others to create a classic GUI automation library, giving you visibility into and interaction with Cocoa GUIs. PyATOM home page

墨洒年华 2024-07-21 00:55:45

您可以查看并考虑 TestPlant(以前称为 Redstone Software)的 Eggplant,网址为 http://www.testplant.com/

这里是苹果去年专门介绍的一篇文章。

You might check out and consider Eggplant by TestPlant (formally Redstone Software) at http://www.testplant.com/.

Here is an article that Apple featured on them last year.

無處可尋 2024-07-21 00:55:45

最新的 CocoaCast 播客采访了《Scripted GUI Testing with Ruby》一书的作者 Ian Dees。 您可以访问 CocoaCast 了解更多信息

The latest CocoaCast podcast has an interview with Ian Dees the author of "Scripted GUI Testing with Ruby". You can find out more at CocoaCast

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