Gaming Your .NET Code Coverage Score

gaming_score_googleBuilding your testing strategy is important to make sure you are measuring what truly matters to build quality .NET applications. Part of this is making sure we are using the right measurements to track our goals. We talk about the importance of metrics a lot on our blog. In fact, if you feel like brushing up, check out our posts on branch coverage, sequence point coverage and change risk anti-patterns score.

Defining metrics is one piece of the code coverage puzzle and your overall testing strategy. The next is finding meaningful benchmarks and scores for tracking and evaluating your code base and your code coverage score. This leads us to the subject of our blog post. We get asked all the time, “How do I get my code coverage score to be 100%?” Or another favorite, “Does a perfect code coverage score mean I have perfect code?” Or “Will 100% code coverage score make QA happy?

Code coverage is most effective when it is integrated into your overall testing strategy and is used as a feedback mechanism. Without a clear understanding of what code coverage means to the testing strategy, people may start gaming the code coverage score to get a 100%. This “perfect score” may give you a false sense of security.

For example, assume you arbitrarily set a coverage threshold of 100% for your code base but it is based on line coverage or method coverage. Did you know the way you structure your modules and write your actual code impacts your coverage results? Using that knowledge, tests can be established to game the code and give a perfect score. However, the code can have areas that remain untested.

Before striving for the perfect score, make sure you understand the metrics you are using and have a solid strategy in place with a goal of moving you towards your ideal score. Looking for more details on how to make the most out of code coverage metrics? We invite you to watch our best practices webinar for suggestions on how to achieve coverage results that work best for your organization. Code on!

Trackbacks

  1. […] Gaming Your .NET Code Coverage Score (Vicky) […]