Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit-testing mouse event 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 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?

like image 285
jpfollenius Avatar asked Dec 29 '22 01:12

jpfollenius


2 Answers

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

like image 51
Marjan Venema Avatar answered Dec 31 '22 14:12

Marjan Venema


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.

like image 34
CloudyMarble Avatar answered Dec 31 '22 13:12

CloudyMarble