Documented unittests & code coverage

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 28 22:12:58 PDT 2016


On 7/28/2016 9:48 PM, Jonathan M Davis via Digitalmars-d wrote:
> gives some good examples of why having the unittest blocks themselves
> counted in the total percentage is problematic and can lead to dmd's code
> coverage tool listing than 100% coverage in a module that is fully tested.
> What's critical is that the code itself has the coverage testing not that
> the lines in the tests which are doing that testing be counted as part of
> the code that is or isn't covered.
>
> I know that it will frequently be the case that I will not get 100% code
> coverage per -cov for the code that I write simply because I frequently do
> stuff like use scope(failure) writefln(...) to print useful information on
> failure in unittest blocks so that I can debug what happened when things go
> wrong (including when someone reports failures on their machine that don't
> happen on mine).
>
> D's code coverage tools are fantastic to have, but they do need a few tweaks
> if we want to actually be reporting 100% code coverage for fully tested
> modules. A couple of other reports that I opened a while back are

As soon as we start taking the % coverage too seriously, we are in trouble. It's 
never going to be cut and dried what should be tested and what is unreasonable 
to test, and I see no point in arguing about it.

The % is a useful indicator, that is all. It is not a substitute for thought.

As always, use good judgement.



More information about the Digitalmars-d mailing list