单元测试MFC UI应用程序? [英] Unit testing MFC UI applications?

查看:429
本文介绍了单元测试MFC UI应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何单元测试大型MFC UI应用程序?

How do you unit test a large MFC UI application?

我们有几个大型MFC应用程序已经开发多年,我们使用一些标准自动化QA工具运行基本脚本以检查基本原理,文件打开等。这些是由QA组在每日构建之后运行。

We have a few large MFC applications that have been in development for many years, we use some standard automated QA tools to run basic scripts to check fundamentals, file open etc. These are run by the QA group post the daily build.

但是我们想引入程序,个人开发人员可以在向日常版本提交代码之前构建并运行针对应用程序的对话框,菜单和其他可视元素的测试。

But we would like to introduce procedures such that individual developers can build and run tests against dialogs, menus, and other visual elements of the application before submitting code to the daily build.

我听说过隐藏的技术

环境是C ++ / C / FORTRAN,MSVC 2005,Intel FORTRAN 9.1,Windows XP / Vista x86& x64。

Environment is C++/C/FORTRAN, MSVC 2005, Intel FORTRAN 9.1, Windows XP/Vista x86 & x64.

推荐答案

这取决于应用程序的结构。如果逻辑和GUI代码是分开的(MVC),那么测试逻辑很容易。查看Michael Feathers Humble对话框(PDF)。

It depends on how the App is structured. If logic and GUI code is separated (MVC) then testing the logic is easy. Take a look at Michael Feathers "Humble Dialog Box" (PDF).

编辑:如果你考虑它:你应该非常仔细地重构如果应用程序没有这样结构。没有其他技术来测试逻辑。模拟点击的脚本只是划伤表面。

If you think about it: You should very carefully refactor if the App is not structured that way. There is no other technique for testing the logic. Scripts which simulate clicks are just scratching the surface.

其实很容易:

假设你的控制/窗口/任何改变列表框的内容用户点击一个按钮,你想确保列表框中包含正确的东西后点击。

Assume your control/window/whatever changes the contents of a listbox when the user clicks a button and you want to make sure the listbox contains the right stuff after the click.


  1. 重构,以便有一个单独的列表中列出要显示的列表框的项目。项目存储在列表中,并且不会从您的数据来自。使列表框列表的代码只知道新的列表。

  2. 然后创建一个包含逻辑代码的新控制器对象。处理按钮点击的方法只调用mycontroller-> ButtonWasClicked()。它不知道列表框或任何其他。

  3. MyController :: ButtonWasClicked()需要对预期的逻辑执行操作,准备项目列表并通知控件进行更新。为了工作,你需要通过为控件创建一个接口(纯虚拟类)来解耦控制器和控件。控制器只知道该类型的对象,而不是控件。

控制器包含逻辑代码,并且仅通过接口知道控制。现在你可以通过模拟控件,为MyController :: ButtonWasClicked()编写常规单元测试。如果你不知道我在说什么,阅读Michaels的文章。两次。然后,再次。

(自我注意:必须学会不要to得太多)

Thats it. The controller contains the logic code and knows the control only via the interface. Now you can write regular unit test for MyController::ButtonWasClicked() by mocking the control. If you have no idea what I am talking about, read Michaels article. Twice. And again after that.
(Note to self: must learn not to blather that much)

这篇关于单元测试MFC UI应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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