DRYing my UI and BYOC

by Rob Kitson

Of course I'm referring to the Do not Repeat Yourself principle, but in this case I'm focusing on not repeating my UI development cycle. 

I was working on the prototype of an application about a year ago, and found myself in the middle of an anit-pattern of sorts... change some code/properties, hit F5, click & watch, click & watch, click & watch.... not only was the process slow and painful, but in order to make it easier to test I had hacked in (and had later remove) a few extra methods which were called when the app loaded in order to fill it with test data.

A couple months ago, we decided to scrap the prototype and move on to UI version 2.0.  The model and services are going to stay the same, each have a full suite of tests and satisfy their business requirements, but the UI was weak.  Seeing that it was my first WinForms app, that most of my experience has been in web development, and that I had spent the last year on a console app, I didn't feel too bad about scrapping it.

The thought of redoing all that manual UI testing was too much to bear so I started googling and found a great series of articles by Jeremy D. Miller called Build Your Own CAB.  In them, Jeremy does a great job of explaining how to write code which makes your UI programmatically testable by creating a contract which your UI will implement and is testable through mocking.  Reading through the series, I sometimes found myself trying to figure out where all his example code would go (which project? which file? which namespace?), and whether or not there was missing code.

Looking through the comments on some of the posts, I noticed that a few other people were asking the same question and wanted a full blown .sln with a working example that they could dig into.  I asked Jeremy about this at DevTeach, and told him that I was thinking about putting together some example solutions which I could use to make sure I understood the concepts, and then share them.  Green lighted, I did the first 2 ( Humble Dialog Box, and Supervising Controller), and started a Google Code project called BuildYourOwnCAB

The subversion repository can be found here: http://buildyourowncab.googlecode.com/svn/trunk/

I plan on tackling more examples soon, and would like to do one per week until I'm done.  Since the project is open source I will be happy to accept patches; the better the examples are the more we are likely to learn from them.