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:
TPC = (CT + CF + SC + MC)/(2*C + S + M){excerpt}
where
CT - conditionals that evaluated to "true" at least once CF - conditionals that evaluated to "false" at least once SC - statements covered MC - methods entered C - total number of conditionals S - total number of statements M - total number of methods
Coverage metrics in XML report file
The XML report file produced by Clover contains the <metrics> tag with a number of attributes. For instance:
<metrics
coveredelements="221" complexity="123" loc="707" methods="100" classes="37"
statements="209" packages="1"
coveredconditionals="12" coveredmethods="42"
elements="337" ncloc="379" files="11"
conditionals="28" coveredstatements="167"/>
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.
Note: the <metrics> tag in XML report contains one extra attribute pair, which is calculated as follows:
- coveredelements = coveredconditionals + coveredstatements
- elements = conditionals + statements
Precision of coverage percentages
Coverage percentages in Clover's reports are always rounded to one decimal place
(for example 35.2%). This is not configurable.
If you need a higher precision, you have two options:
- Compute it yourself from the XML report. The
<metrics>tag shown above contains the raw counts, so you can calculate the percentage at any precision. See How can I download the report or extract coverage metrics? - Use a precise coverage target. The
<clover-check> task and the
clover:checkgoal compare the actual value against the target with as many fractional digits as the target declares, usingBigDecimal.ROUND_HALF_EVENrounding. For example, if the actual coverage is 99.9% then a build passes fortarget="100%", but fails fortarget="100.000000%".