Developing an application with WinForms can lead to difficult testing scenarios. There are a ton of automated UI testing toolkits that essentially record workflows and replay them. This can work, but leads to unwieldy tests, and makes it difficult to integrate them into automated tests and builds. I recommend using the Model View Presenter (MVP) pattern for your application architecture to relieve this pain point. Todd Snyder from Infragistics has a nice blog entry explaining the differences between MVC and MVP patterns. The gist is: you have a coordinating Presenter that communicates with the View via its interface, and orchestrates the interaction between the View and the Model. The important piece here is the View interface. This view interface can allow you to stub or mock the view in testing scenarios, to completely eliminate the need for any UI interaction. As long as your UI code is used as a shell that does nothing but pass messages, this makes testing REALLY easy.
We recently built a project around the MVP architecture. Eventually we wound up creating a test harness providing us simple methods such as:
public void MouseUp(IDocumentPresenter presenter, int x, int y)
This simulated a mouse up event without actually requiring an input device or the UI that it acts upon. With simple method like these, you can build up some pretty complex tests that run quickly and don’t require any special libraries to run.
Before embarking on your next GUI framework based application, be it WinForms or other, evaluate the MVP pattern and the ease of testing that it can provide. It’s worked really well for us.


Nice post and link to Infragistics. One question though. Is it possible to use MVP(Passive) for and ASP.NET and also incorporate AJAX functionality without breaking the pattern. A little confused on best practices to follow in this scenario.