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

查看:55
本文介绍了如何对 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 中抽象出尽可能多的逻辑.关于此的一篇非常受欢迎的文章是 The Humble Dialog Box" 作者: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天全站免登陆