MFC GUI可通过Google测试进行测试? [英] MFC gui testable with google test?

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

问题描述

我一直使用gtest作为我的C ++单元测试框架,它非常适合控制台应用程序.有人知道是否可以使用此方法(或将是一个很好的替代方法)来测试MFC应用程序吗? 我的意思是,根据GUI的事件(文本框中的文本,按钮的单击等)进行自动测试. 我见过类似TestComplete的应用程序,但是我想知道gtest是否提供类似的东西,或者是否有免费/开源替代品.

I have been using gtest as my C++ unit-test framework, and it works great for console applications. Does anybody know if it is possible to use this (or which would be a good alternative) for testing an MFC application? I mean, make an automatic test depending on the events of the GUI (text inside text-boxes, buttons clicks and so). I have seen applications like TestComplete, but I would like to know if gtest offers something similar or if there is a free/opensource alternative to start with.

推荐答案

我也一直尝试做同样的事情,到目前为止,我的解决方案是在Windows应用程序和控制台应用程序之间来回移动:

I've been trying to do the same thing as well, and so far my solution has been to go back and forth between a windows application and console application:

如果以上链接无效,则在属性页中,

If the above link is dead, then in property pages,

链接器->系统->子系统->选择控制台"

Linker -> System -> SubSystem -> Choose "Console"

C/C ++->预处理程序->预处理程序定义->将"_WINDOWS"更改为"_CONSOLE"

C/C++ -> Preprocessor -> Preprocessor Definitions -> Change "_WINDOWS" to "_CONSOLE"

然后确保您有一个.cpp文件,该文件具有main()函数,并且所有 测试所有后端逻辑所必需的#includes.如果您切换回 Windows应用程序,我发现它只是忽略了您的主要功能 不会与WinMain()发生任何冲突,因此您无需进行任何繁琐的注释,也可以进行其他操作.无论如何,这都是一个棘手的解决方案,我仍在做一些研究和实验.

Then make sure you have a .cpp that has a main() function with all the necessary #includes to test all the backend logic. If you switch back to a windows application, I found that it just ignores your main function without any conflict with WinMain(), so you don't need to do any tedious commenting out or what not. In any case, it's sort of a hacky solution, and I'm still doing some research and experimenting.

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

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