Test Code is as important as Production Code
I attended CITCON in Sydney and one theme that I took away from the conference is “Test Code is as important as Production Code”. Too often test code is seen as the poor cousin that does not need any attention. Common code is “copied and pasted” instead of being consolidated and reused. This results in test code that takes longer to update then the production change. A sure sign that things have gone off track is when the team says “it will take twice as long to change the test code as it will the production code”. When it comes to testers test code it gets worse! Badly commented, stuck together with bits of string and not even version controlled. Test code should have a design, regularly be re-factored, the DRY (Don’t Repeat Yourself) principal should be followed as well as standard coding techniques (version control, commenting, naming conventions etc). Treat your test code the same as you do production code and the project will be better off for it.
At the conference you also made a very good point about the need to test the tests (by injecting failures). Perhaps this should be done as part of the CI process so that there is some guarantee that the test suite is still relevant.
Another approach that someone mentioned was to include test code changes in peer reviews. If nothing else, this should discourage the sticky-tape programming style.
I agree with you Kristan. Unit and integration testing is often the bulk of the code that I write on projects. The sheer volume of tests makes problems with test code a real pain point of the project. Maintenance of tests is arguably harder than production code. As soon as we allow ourselves some leniency on test code quality we’re on a slippery slope destined for disaster.
With tools like Selenium RC there is really no excuse to write badly factored acceptance tests (http://tomasvarsavsky.com/2007/07/27/selenium-page-models/). What I struggle with is the role of the tester in the team. Traditionally testers are not developers. Testers have been exposed to code through recording test tools but don’t generally have the design skills that are at the core of a good developer. Is it fair to expect testers to write well factored acceptance tests? Are we at a point where we need a new generation of testers that are code savvy? I think this generation of testers is well on it’s way, we just need more of them in the market!
I agree testing code is important, but not sure If I should treat it as production code, and if you want to apply costly SCM processes to test code, it will slowdown entire maintanance cycle, wouldn’t it? IMO, Test code is better not treated as sensitively in some situation like maintainance but should be open for modification.