unit-testingtestingtdd

How do you measure the quality of your unit tests?


If you (or your organization) aspires to thoroughly unit test your code, how do you measure the success or quality of your efforts?


Solution

  • My tip is not a way to determine whether you have good unit tests per se, but it's a way to grow a good test suite over time.

    Whenever you encounter a bug, either in your development or reported by someone else, fix it twice. You first create a unit test that reproduces the problem. When you've got a failing test, then you go and fix the problem.

    If a problem was there in the first place it's a hint about a subtlety about the code or the domain. Adding a test for it lets you make sure it's never going to be reintroduced in the future.

    Another interesting aspect about this approach is that it'll help you understand the problem from a higher level before you actually go and look at the intricacies of the code.

    Also, +1 for the value and pitfalls of test coverage already mentioned by others.