Code Coverage Awareness
Understanding the various aspects of test coverage is the first step towards creating effective test suites. Coverage awareness is the next step.
If you have not already done so, you should obtain a free or commercial tool for measuring the coverage that your unit tests actually achieve. Make sure that you understand exactly what coverage granularity and coverage criteria the selected tool supports. You should immediately add test cases for covering source code that is not yet covered—possibly, by means of additional tools that can automatically generate tests for existing source code.
Today, a coverage goal of 70% to 80% of statement or, preferably, branch coverage is fairly standard (and pretty realistic for most types of applications). However, keep in mind that statement or branch coverage, as well as merely line-based coverage granularity, can be misleading.
Tools that support automated flow analysis can assist in finding additional interesting code paths. Expressions that can potentially throw exceptions can be used as starting points for manually identifying new interesting code paths in a bottom-up fashion. Additional tests that use “corner case” inputs and perturbations of existing inputs can be used to safeguard against future regressions. As an additional measure, parameterized testing can help to separate input data from test structure.
If possible, test overlap should be minimized by selecting one representative input from each equivalence class of test inputs. Coverage density analysis may be used to achieve evenly-distributed execution frequencies for tested code. All coverage metrics should be monitored over time to ensure continuous improvement of code quality.
To explore code coverage white papers, articles, and videos/webinars, visit our Code Coverage Resource Center. Or, visit Parasoft's Code Coverage Analysis page.
Image credit: jimkster