2024 Public Training Schedule
December 9 – 12, 2024 – Agile Analysis and Design Patterns
Half-Day Sessions
(c) 2024 To Be Agile
How much code coverage should we have? I say 100%. Do we really need to test getter and setter methods? No and yes. We don’t need to verify the trivial behavior of getters and setters but it can be valuable to have a test for them so that their existence is specified. Likewise, I have tests for defined constants so that if a value changes a test will fail.
I know that some people say you don’t need these kinds of tests and I am ok with that. It is true, we don’t need them. But I want my tests to fully specify the behavior of my code such that if I lost all my code but not my tests then I could easily reconstruct my code by looking at my tests.
Sometimes we forget to write a complete set of tests. There should be enough boundary tests to fully specify a boundary condition. For simple numeric values this is often just one test for the low end boundary, one for the high end boundary and tests for special cases such as zero.
If every method we write is preceded by writing a test that expresses a single intention of the system then we will have the right amount of code coverage. Not too many tests and not too few.
Previous Post: « Triangulation
Next Post: Reflections on the Three Steps of Test First Development »