I ran into the same problem, so I spent a bit of time redesigning the answer by donating it to Stack Overflow.
For each Java assert -statement, Cobertura tracks two conditions:
- Does this assert statement run with a check for enable or disable?
- Whether the predicate determines true or false.
Thus, four results are possible. The information provided for this line in the HTML report consists of
- result for condition 1 (0-2 possibilities are taken from 2, addressing with verification is enabled or disabled),
- and the result for condition 2 (0-2 opportunities taken from 2: affirmation or failure).
- overall result (0-4 of 4),
Typical scenario:
Launch Cobertura once, while approval verification is disabled. You'll get:
Enabled / Disabled: 50% (disabled); Passed / Failed: 0% (not reached); Consequently, a total of 25%.
Cobertura will report this as
Conditional coverage 25% (1/4) [each condition 50%, 0%]
Launch Cobertura once, with validation approval enabled. Usually your statements are always true, so you get:
Enabled / Disabled: 50% (Enabled); Passed / Failed: 50% (always true); Therefore, in general: 50%.
Launching Cobertura twice, once with claims verification enabled and once. Assuming the statements are always true, we get:
Enabled / Disabled: 100% (both on and off); Passed / Failed: 50% (always true); Consequently, a total of 75%.
Then, if we add test cases that guarantee that this statement fails at least once and passes at least once, we get all the numbers 100%.
Please note, however, that if you use assertions in the design style of the contract, you will usually not even be able to make them fail, see Cobertura's answer to another overflow question and the assert keyword .
Finally: although the abstract numbers are explainable, I am not sure that they are very useful. My preference would be to omit the assertion cover from the general reports. Clover can do this, but I donβt know about an open source coverage analysis tool with this nice feature.
avandeursen
source share