I bumped into the same issue, so I spent a bit of time to reverse engineer the answer, donating it to Stack Overflow.
For each Java assert
-statement, Cobertura keeps track of two conditions:
- Whether a given assert statement was executed with assertion checking enabled or disabled.
- Whether the predicate actually evaluates to true or to false.
Thus, a total of four outcomes are possible. The information provided
for a given line in a HTML report consists of
- the outcome for condition 1 (0-2 possibilities taken out of 2, addressing execution with checking enabled or disabled),
- and the outcome for condition 2 (0-2 possibilities taken out of 2: assertion pass or fail).
- the overall outcome (0-4 out of 4),
Typical scenario's are:
Running Cobertura once, with assertion checking disabled.
You'll get:
Enabled/Disabled: 50% (disabled);
Passed/Failed: 0% (not reached); Hence overall 25%.
Cobertura will report this as
Conditional coverage 25% (1/4) [each condition 50%, 0%]
Running Cobertura once, with assertion checking enabled.
Typically your assertions are always true, hence you get:
Enabled/Disabled: 50% (enabled);
Passed/Failed: 50% (always true); Hence overall: 50%.
Running Cobertura twice, once with assertion checking
enabled, and once without.
Assuming assertions are always true, we get:
Enabled/Disabled: 100% (both enabled and disabled);
Passed/Failed: 50% (always true); Hence overall 75%.
Then, if we add test cases that ensure that a given assertion
fails at least once, and passes at least once, we get
all numbers at 100%.
Note, however, that if you use assertions in the style of design by contract,
you will generally not even be able to make them fail,
see the answer to another Stack Overflow question, Cobertura coverage and the assert keyword.
Finally: while theses numbers are explainable, I am not sure that they are very useful. My preference would be to be able to omit assertion-related coverage from the overall reports. Clover can do this, but I'm not aware of an open source coverage analysis tool with this nice feature.