Jakew
Consulting, hacking, and motorcycles

Write code to be tested!

Monday, 17 November 2008 07:38 by jakew

When  you are developing your code, write in a fashion that makes it very easy to test. Meaning that a n00b to your project should be able to get the project out of subversion open it up in Visual Studio and hit F5.  The NUnit Window should come up and when the tests are run they should all pass.  It should be that easy to get started.

When the n00b goes to add new features or fix bugs adding unit tests should not require any elaborate additional work in order to get the test added to the suite.  Just go in lay down the unit tests and hit F5 again and so on.

This is simply an application of "Do the simplest thing first".  Failure to abide by this will lead to being the owner of a pile of crap.  By making things difficult for the n00b, and everybody else, eventually they will break the overall pattern and style of the project making the code become brittle.  Further, they will quit writing unit tests and won't run existing unit tests. In a very short amount of time the effort to get the unit tests running again will seem equal to the effort to just ship the product. 

Go ahead and try to make the argument about other people being disciplined about adding unit tests.  To which my response is: yeah - be disciplined and make things easier for other people.  Expecting other people to change their behavior to suit you is typically not a winning strategy.

Seriously - make it easy for other people to test your code.  It will pay you back in huge dividends in the long run.

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed