单元测试现有 UI 代码 [英] Unit Test existing UI code

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

问题描述

我浏览了一段时间互联网和这个网站,但没有找到一些方法来对我现有的代码进行单元测试,唯一的发现是将逻辑和与用户的交互分开(MVC 方法).尽管这对于新项目来说非常有用,但它非常耗时,因此对现有项目进行投资过于昂贵.有没有办法为现有的 GUI 项目创建特定的单元测试,理想情况下是自动化的,不幸的是,这些项目直接连接到数据库或其他系统以获取数据,并且数据在显示之前被操作?目前我们有两个项目,一个是 MFC,另一个是 C# .net 2.0 非常感谢.

I was browsing for a while the internet and this site and instead of finding some ways to unit test my existing code the only finding was to separate logic and interaction with the user (MVC approach). Although this is great for new projects it is time-consuming and as a result too expensive to invest for existing ones. Is there a way to create specific unit tests, ideally automated, for existing GUI projects that unfortunately connect directly to databases or other systems to get data and the data are manipulated before it is shown? Currently we have two projects the one being MFC, the other C# .net 2.0 Thanks a lot.

推荐答案

考虑到您无法更改现有代码(更不用说您没有真正对 UI 进行单元测试),单元测试不会在这里介入.您应该寻找某种 GUI 测试自动化/脚本工具.像 Sikuli.从字面上引用他们网站的第一段:

Unit testing won't cut in here considering you can't change your existing code (not to mention you don't really unit test UI). You should look for some kind of GUI testing automation/scripting tools. Like Sikuli. Quoting literally the first paragraph from their website:

Sikuli 是一种使用图像(屏幕截图)自动化和测试图形用户界面 (GUI) 的视觉技术.

Sikuli is a visual technology to automate and test graphical user interfaces (GUI) using images (screenshots).

没有比这更简单的了.您告诉"工具它应该观察/交互 UI 的哪些部分,它会记录并重放它.浏览本演示文稿让您了解您可以做什么(也可以查看他们的视频).可能无法解决您的所有问题,但可能是值得考虑的替代方案.

It doesn't get any simplier than that. You "tell" the tool which parts of your UI it should observe/interact, it records and replays it. Skimming through this presentation will give you idea of what exactly you can do (might also check their video). Probably won't solve all your problems, but might be alternative worth considering.

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

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