Clover.xml : Number of covered lines

Raphael Br August 21, 2013

Hello

When I run tests, I get a clover.xml file that contains tags and attributes like this:

<metrics conditionals="664" methods="117" classes="13" files="9" packages="1" coveredstatements="1554" complexity="710" loc="3620" ncloc="3203" coveredmethods="105" coveredconditionals="479" statements="1989" coveredelements="2138" elements="2770"/>

Among the attributes, we find methods and coveredmethods, statements and coveredstatements, ...
I'm interested in number of code lines, and the number of covered code lines.
Is there a way to have them in clover.xml, preferably in the same metrics tag?

Thanks in advance..

2 answers

1 accepted

2 votes
Answer accepted
jjaroczynski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2013

loc="3620" is the number for Lines Of Code.

I think that ncloc="3203" is the number for Non-Comment Lines of Code as per https://confluence.atlassian.com/display/CLOVER/clover-report

Actually there is no point in "Covered Lines of Code" number. "Covered Statements" is very well describing the coverage.

Cheers,
Jacek

Raphael Br August 21, 2013

I see.
But can you please further explain why "cover lines of code" number is not a good metric for coverage? An example would be very appreciated.
Thank you.

Raphael Br August 21, 2013

I see.
But can you please further explain why "cover lines of code" number is not a good metric for coverage? An example would be very appreciated.
Thank you.

jjaroczynski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 22, 2013

There are 3620 lines of code. Comments and empty lines cannot be covered so we can only consider lines with the real code to cover.

You have 1989 statements. Some of them probably span multiple lines so let's assume there are 2000 lines of code containing statements.

Next let's assume that all your code is covered (all 1989 statemetns and thus all 2000 lines). It means that your code is fully covered (1989 statements in total / 1989 statements covered = 100%). This is very good existing metric.

On the other hand there are: 2000 lines with code covered / 3620 lines in total = 55%. If you add more comments or empty lines (e.g. licensing information) then the number will drop below 55% while still all your code will be covered.

This 55% simply says nothing.

In order to make it reasonable we would need to find "number of lines containing statements" and compare with "number of covered lines containing statements" to get meaningfull 100% - but this is actually duplicate of what we have now: number of statements and number of covered statements.

Does this answer your question?

Cheers,
Jacek

Raphael Br August 22, 2013

Yes. Thank you so much :)

0 votes
dirkd August 21, 2013

Hi Raphael,

doesn't "loc=3620" represent your (covered) lines of code and "ncloc3203" the uncovered LOC?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events