check which branches are covered

1,796 views
Skip to first unread message

colm.ha...@gmail.com

unread,
Dec 3, 2012, 4:35:27 AM12/3/12
to jac...@googlegroups.com
Hi Guys,

I'm currently investigating a way of finding which branches are executed from my system tests. If I view the XML report I can get the info but it only gives me 'how many' branches have been covered and not 'which' branches.

I got everything working fine in terms of generating the jacoco.exec file and can view the 'which' info in the generated HTML reports.

So it's clear that jacoco has this info and 'paints' the HTML reports accordingly but this info does not seem to appear in the XML report where I could parse it out.

The issue I have is that I want to be able to parse the coverage info 'automatically' to determine if the new tests have covered any additional branches. If they have I can add them to my test suite and if not I can dispose of them as 'already covered'. I can tell if coverage has increased but it would be better if I could 'map' tests to actual branches covered.

Is there some way I could extend the jacoco source to get this info or maybe use the API.

I managed to do something similar in the old EMMA source by simply printing out to console and redirecting to a file but I need this in our new Java7 code base:

File: core\java12\com\vladium\emma\report\MethodItem.java
Line: 103
Insert: System.out.println("Block "+parent.m_cls.getClassVMName()+"."+method.getName()+"."+b+" covered");

Anyone else come across this issue or have any ideas ?

Thanks and regards,
Colm

Marc R. Hoffmann

unread,
Dec 3, 2012, 12:41:21 PM12/3/12
to jac...@googlegroups.com
Hi Colm,

I'm not sure whether I understand you request correctly. JaCoCo reports
branch coverage on line level granularity. I.e. for every line the
number of covered branches vs. the number of missed branches is reported
-- in the HTML report as well as the XML report. You might look at this
example:

http://www.eclemma.org/jacoco/trunk/coverage/coverage.xml

Here is the schema including documentation:

http://www.eclemma.org/jacoco/trunk/coverage/report.dtd

If your report does not include line level information this is probably
due to the fact that your class files do not contain debug information.
Please see FAQ for this:

http://www.eclemma.org/jacoco/trunk/doc/faq.html

Best regards,
-marc

Colm Harrington

unread,
Dec 3, 2012, 4:56:10 PM12/3/12
to jac...@googlegroups.com
Thanks for the reply Mark, i'll check the debug parameter in the pom.xml.
I appreciate the help ...

Regards,
Colm

Colm Harrington

unread,
Dec 4, 2012, 6:51:15 AM12/4/12
to jac...@googlegroups.com
Ah great, it works !! Now I have the info I need in the XML.

The other thing I was wondering is:

Is there a more efficient way than parsing the XML report for coverage data? Maybe it is possible to query POJOs in real time via the API for this information ?

Regards,
Colm

Colm Harrington

unread,
Dec 4, 2012, 11:55:44 AM12/4/12
to jac...@googlegroups.com
OK, ignore my last post, I found those nice examples at:


I'll work through those to see if they can help me solve my issue ...

/
Colm

Colm Harrington

unread,
Dec 10, 2012, 5:19:48 PM12/10/12
to jac...@googlegroups.com
Hi Guys,

I've been looking through the XML reports and noticed that a line like:

private static final Log LOG = LogFactory.getLog(xxx.class);

 gives a coverage report of:

<line nr="30" mi="0" ci="4" mb="0" cb="0"/>

What makes up the 4 instructions in this line of code?

Regards,
Colm

Marc R. Hoffmann

unread,
Dec 11, 2012, 12:44:47 AM12/11/12
to jac...@googlegroups.com
Hi Colm,

the number are byte code isntructions. See documentation for exact
counter definitions:

http://www.eclemma.org/jacoco/trunk/doc/counters.html

If you look at th bytecode of your class (javap or Eclipse bytecode
viewer) you will see the instructions in the <clinit> method.

Best regards,
-marc

On 10.12.12 23:19, Colm Harrington wrote:
> Hi Guys,
>
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages