开发者

Unit-testing mouse event handlers

开发者 https://www.devze.com 2023-02-09 09:48 出处:网络
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:

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. Simulate 开发者_如何学Cmouse 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?


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

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.

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).


Usually you are supposed to write your code in a way you can test it, so you test the methods you call by the mouseevent without simulating the mouse event.

In order to do that you need a good separated GUI and logical middleware.

Can you maby provide some Code or more information on the funcions you call on the mousevents in your app.


I think you are looking for some automated GUI testing. You could try Test Complete from Smart Bear, for example.

DUnit does offer some basic GUI testing facilities (in the GUITesting unit) but I don't think it may not be comprehensive enough for your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号