I recently came across an old entry on a Blog that outlined the stories that a consultant was using in introducing Unit Testing concepts and practices to a group of developers.
What a great idea! They are a concise list of driving principles, guiding his activities. They could be easily turned into some measurable benchmarks, milestones that indicate how far the team has come and how much more work the consultant still has.
I am envious. I began doing something similar - introducing Unit Testing to a group of developers - a couple years ago. I became the team's Unit Test Evangelist, championing the practice.
I had some benefits of unit testing that I wanted them to grasp and run with. But I did not take the time at the outset to clarify to myself or articulate to the team's management, exactly what we hoped to achieve.
And of course without knowing what you want to achieve, it becomes harder to know if you succeeded. How will you know you are there when you don't have a clear idea of where you are going?
An unspoken goal of mine was that the developers would see the benefits of automated unit tests, and would join me in improving our software by creating, running and maintaining them. What were the benefits I sought to persuade them with?
In my experience, some of the key benefits of Unit Testing are:
• Unit Tests find future bugs;
• Unit Tests increase your confidence in the code you are creating;
• Unit Tests save time by reducing the amount of repetitive manual testing needed;
• Unit Tests save time by preventing future debug sessions;
• Unit Tests document expected behavior;
• Unit Tests shorten the feedback loop, allowing fixes to come when the sub-domain is freshest in mind;
• Unit Tests drive better design;
• Unit Tests make changing existing code safer;
More than two years after introducing the concepts to this team, I would judge my success as middling at best. Again, with no a priori goals and measurables, that is difficult to assess. I will save my thoughts on why the results have been a little disappointing, and what I might do differently both from now on and another time, for another post.