单元测试鼠标事件处理程序 [英] Unit-testing mouse event handlers

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

问题描述

单元测试组件时,出现以下问题:

When unit-testing a component, the following question occured to me:

有许多与鼠标有关的事件处理程序。我看到两种可能性来测试这些处理程序:

There are a number of mouse-related event handlers. I see two possibilties to test these handlers:


  1. 使用Windows API调用模拟鼠标事件

  2. 使用受保护的黑客访问受保护的事件处理程序,并直接调用它们。 / li>
  1. Simulate mouse events using Windows API calls.
  2. Use the protected hack to access protected event handlers and call them directly.

我知道单元测试通常限于类的接口(这也意味着测试不必在类内部变化),但这种情况是值得例外吗?

I know that unit testing is normally restricted to the interface of a class (which also means that tests don't have to be changed when class internals change), but is this scenario worth an exception?

在单元测试组件时,通常如何处理鼠标事件?

How do you usually handle mouse events when unit-testing components?

推荐答案

我个人认为,您需要一个架构更改,以方便自动化用户界面测试。为什么在这篇文章中很好地制定了原因: http://blog.objectmentor.com/articles/2010/01/04/ui-test-automation-tools-are-snake-oil

Personally, I think you need an architectural change to facilitate automated user interface testing. Reasons why are well formulated in this article: http://blog.objectmentor.com/articles/2010/01/04/ui-test-automation-tools-are-snake-oil

Delphi杂志曾经有一篇关于用代码自动测试用户界面的有趣的文章(没有特定的gui测试工具)。比我预想的要长一点,可能不在线。如果我找到它将会更新我的答案。

The Delphi Magazine once had an interesting article on automated testing of user interfaces from code (without a specific gui testing tool that is). Taking a bit longer to find than I expected and may not be available online. Will update my answer when/if I find it.

文章是由Julian Bucknall(DevExpress)创建的易于测试的用户界面,并在德尔福杂志。不幸的是,这篇文章已经不在线了。您将不得不购买Delphi Magazine的全部集合:1 GB USB记忆棒,所有问题和所有代码均已在Delphi杂志上发表。很值36英镑! (不,我没有得到佣金)。

The article is "Creating Easily Testable User Interfaces" by Julian Bucknall (DevExpress) and was published in issue 120 of "The Delphi Magazine". Unfortunately the article is no longer online. You would have to buy the total collection of The Delphi Magazine: a 1 GB USB stick with all issues and all codes ever published in The Delphi Magazine. Well worth the 36 GBP! (And no, I do not get a commission).

这篇关于单元测试鼠标事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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