Jun 13, 2009

On test writing discipline and gains

Hi.

Let's start this post with the usual disclaimers :). Actually, I have only one: Everything discussed here is related to my own experiences with unit testing and/or TDD in the last years.

In fact, I have been in contact with some sort of more formal testing procedures for some time now; in the early days it was more a desperate act trying to avoid SDD (sorry if I use potentially valid acronyms here), i.e, 'Shame Driven Development'. Since most of my code have no tests at all (other than the usual driver application that covered only the changes being applyied at the moment), it was not uncommon to have some developer, tester or even final users approaching me and complaining about some broken feature in a just released version of the module I've worked on (whence the shame). Of course the usual problems of lacking good tests were plain visible: resistance to refactor / change code, lack of confidence whether a piece of code was good enough or not, no sensible metric to declare completeness, regressions all over the place, etc.)

After understanding (thanks to my coach :) the importance of having a well developed ( one that values readability, maintainability, expressiveness, in the sense of making clear test intents, completeness, etc) test suite, finding the time and motivation to write such tests became easier. Even though understanding the benefits of having such tests, the urge to get something working, and so that it could be shown (to managers, clients, whoever), made me tempted to skip the test writing (remember, I haven't get into the TDD mind set yet, so tests were seen as a post development phase).

In these early days, most of my teammates had little or no idea of the concept of unit testing and it was hard to convice them that it worths the time dedicated to write such tests. Anyway, sometimes I took the burden upon myself and wrote unit tests (even though no time was allocated to that). Of course everybody noticed that my code was less buggy and that I was less concerned aboud changing it :)

Some years have passed and even though doing my best to start my coding sessions with a test I must admit that I am not a TDD practitioner yet, at least not in the strict sense of the definition. This becomes clear when it comes to my personal projects: most of them have no tests at all :(.

But thanks to some embarrassing episodes (related to one of these personal projects) (and to my coach :) I had finally decided to do "the right thing(tm)" and I am writing the tests I should have writen long before :) (guess what, I've already found hidden bugs). I am even using a nice mock library for .Net called Moq.

Of course I am starting to see the pays off of pursuing this goal :)

Best regards (and have fun!)

Adriano

No comments: