Wednesday, December 21, 2005

This is about DotNet

This blog is about DotNet. I'm a founding member of the csUnit team. In this blog I'd like to focus on general and special .NET 2.0 questions. Feedback is most certainly welcome!

2 comments:

John Stodden said...

I have recently started to use csunit and find it excellent for testing c# classes. However I would also like to test GUI forms and am not sure how to proceed. Does the current version support this?

thank you!

Manfred said...

John, absolutely you can use csUnit to test GUI forms as well. It is challenging though. All forms use an event-driven model. An event is fired and your code may provide an event handler. E.g. a button is clicked, and you have written some code to be executed when the button is clicked. The question is now how you would like to test this.

Option 1 is certainly to fire the event on the form. Then you need to determine when the event handler has finished. There might, however, be several event handlers for the same event. So how do you know that all of them have finished? Each of them might potentially be executed on a different thread. Or one of the event handlers might require a lengthy operation and spawns a new thread and returns immediately. The thread continues to run. How do you know when it is finished?

So maybe option 2 is more compelling. What if you could invoke the event handler directly and test whether the handler did what you expected? That way you don't need to wait because the handler is executed on the same thread as your test. In this case, however, you haven't guaranteed that if a specific event is fired the particular event handler is actually invoked. But maybe you can write a test for this as well?

In summary: This is just very brief, but it highlights that csUnit does not prevent you from doing these things. It is however quite challenging and at times very difficult to find a proper solution. I would be happy to hear more about how you tackled this problem.

Post a Comment

All comments, questions and other feedback is much appreciated. Thank you!