views:

717

answers:

2

Thanks to ASP.NET MVC framework, it became possible to unit test web applications. But how do you unit test windows forms applications?

+2  A: 

One way is to use Model View Presenter (MVP) Patterns for Winforms app. Pretty easy to adapt if you already worked with MVC

Specifically, take the view part of MVC and slice it as thin as possible so that it is only a skin around the actual UI components and make it completely passive. The controller, now called the "presenter," is responsible for all interaction with the rest of the system.

Read some great articles from.

Dan Bunea - Click to read

Jeremy Miller - Click to read

Happy coding

amazedsaint
A: 

The typical pattern seems to be the MVP pattern. The test would be executed against a mocked form.

I've also been experimenting with mockable input abstractions and showing the forms while testing. It's easy enough to fill in values in a form as long as popups are out of the way.

In the end the most worthwhile path might be factoring out unit-testable code and just using some UI testing framework for the UI.

Cristian Libardo