Anyone that is a practitioner of testing or specially TDD knows that the quality of your tests are a direct measure in the assumed quality of your tested code. Better put, if your tests suck, you can assume very low quality from your code.
So what is harder, writing quality code or writing quality tests? My vote is that writing quality test code is harder then writing quality application code.
When it comes to writing 'quality application code' the measure of quality is really in the eye of the developer. What one person calls good code may be called crap by another developer. But as long as the code meets the business needs, it should be at least considered quality (if not simply functional) code.
However, creating quality test code is a little more measurable. One possible way to measure this is by code coverage (please do not take that statement as high code coverage equals high quality as this is NOT the case). Another is to simple make sure the tests exercises as many different business scenarios as practical (notice here I did not say possible because at some point you reach the point of diminishing returns and should just stop). Finally, if you keep your tests compact and focused you should be able to create quality tests.
To me the real measure of quality test code is how maintainable is it? Is it very painful to refactor when the code under test needs to change? If you can maintain your test code with very little friction or effort, they I would say chances are high you have high quality test code.
Hints your test code may be poor quality.
- Test code does not test the intent of the code
- Test code becomes to brittle to maintain going forward
- Test code is heavy (those testing multiple things)
- You dread making changes to your code base for fear of having to modify your test code.
Hints your test code may be of high (er) quality
- Causes very little friction during future code changes
- Test code is light weight, tests only a single concept
- You do not dread making changes to your code base for fear of having to modify your test code.
So, what do you think? Which is harder and why?
Till next time,
Posted
05-21-2008 7:31 AM
by
Derik Whittaker