如何对GUI进行单元测试? [英] How can I unit test a GUI?

查看:198
本文介绍了如何对GUI进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中的计算经过了充分的测试,但是由于GUI代码太多,因此我的总体代码覆盖范围比我想要的低。是否有关于单元测试GUI代码的准则?

The calculations in my code are well-tested, but because there is so much GUI code, my overall code coverage is lower than I'd like. Are there any guidelines on unit-testing GUI code? Does it even make sense?

例如,我的应用程序中有图形。我还无法弄清楚如何自动化图形测试。需要人眼的AFAIK来检查图形是否正确。

For example, there are graphs in my app. I haven't been able to figure out how to automate the testing of the graphs. It takes a human eye, AFAIK, to check if the graph is correct.

(我正在使用Java Swing)

(I'm using Java Swing)

推荐答案

像MVP和MVC这样的设计通常会尝试从实际GUI中提取尽可能多的逻辑。关于此的非常受欢迎的文章是 Michael Feathers的谦虚对话框 。就个人而言,我在尝试将逻辑移出UI时有过不同的经历-有时效果非常好,而在其他时候,麻烦则多于其价值。不过,这有点超出了我的专业领域。

Designs like MVP and MVC typically try to abstract as much logic out of the actual GUI as possible. One very popular article about this is "The Humble Dialog Box" by Michael Feathers. Personally I've had mixed experiences with trying to move logic out of the UI - sometimes it's worked very well, and at other times it's been more trouble than it's worth. It's somewhat outside my area of expertise though.

这篇关于如何对GUI进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆