다음을 통해 공유


I like this statement: The 100% coverage practice is costly only when it forces substandard code to be well designed.

And it is from a post of Patrick Smacchia on simple-talk.

Patrick wrote an essay about writing unit testing code in c#, in which I personally found a lot of good points that I could not agree more. For example:

  • Not all classes need to be 100% covered by tests or even covered at all.
  • The 100% coverage practice is costly only when it forces substandardcode to be well designed.

And especially for the second one, I think it is inspirational and encouraging. I faced situations from time to time that for some certain piece of codes/logic, it was difficult to write a comprehensive test suite to cover all the branches. Honestly, most of time when I faced this, I will choose to leave the coverage not to 100% and accept the fact. But after reading this, knowing what, from now on, I will try my best to achieve the 100% coverage by not only writing comprehensive test cases, but also refactoring the “difficult” logic to the best designed, intuitive, and joyful to read codes.

And I mean it.