Q: How are the Clover coverage percentages calculated?The "total" coverage percentage of a class (or file, package, project) is provided as a quick guide to how well the class is covered — and to allow ranking of classes.
The Total Percentage Coverage (TPC) is calculated using the formula:
Coverage metrics in XML report file
The XML report file produced by Clover contains the <metrics> tag with a number of attributes. For instance:
A mapping between the equation and these attributes is as follows:
- CT + CF = coveredconditionals
- SC = coveredstatements
- MC = coveredmethods
- 2 * C = conditionals
- S = statements
- M = methods
In other words, the 'conditionals' attribute is already a doubled number of branches, while the 'coveredconditionals' attribute is a sum of branches evaluated to true and branches evaluated to false.
So in order to calculate the Total Percentage Coverage metric using data from an XML report you have to use the following equation:
The <metrics> tag in XML report contains one extra attribute pair, which is calculated as follows:
- coveredelements = coveredconditionals + coveredstatements
- elements = conditionals + statements