Detailed Line Coverage Report

55 views
Skip to first unread message

luis...@aurea.com

unread,
Apr 10, 2016, 7:52:14 PM4/10/16
to JaCoCo and EclEmma Users
Hey Folks!

I am working with Jacoco for last 16 months with success and I am loving it BUT now I jave a special requirement and I am not getting the desired results because I could t find parameters or API support

I need:

Generate a report containing package, class, line #, covered (true|false).

Ok .. we have samples in Jacoco project to how generate it in API, but my problem is if I analyze classes it will not cover code tested with PowerMock. Ok! I can get jacoco.exec file from maven build job and analyze it ... I got a good number but based on probes ... but I am still needing line covered true or false.

Any one can help me?

Marc R. Hoffmann

unread,
Apr 10, 2016, 11:49:46 PM4/10/16
to jac...@googlegroups.com
Hi,

> Generate a report containing package, class, line #, covered (true|false).


This is exactly what JaCoCo does. If you need APIs please have look at
documentation and examples:

http://www.eclemma.org/jacoco/trunk/doc/api/org/jacoco/core/analysis/package-summary.html
http://www.eclemma.org/jacoco/trunk/doc/examples/java/CoreTutorial.java

> but my problem is if I analyze classes it will not cover code tested with PowerMock.


This is a different story. JaCoCo works on class files and requires that
the class files instrumented at runtime are the same than the one used
while analyzing exec files. Please see this page for a detailled
discussion and possible work-arounds:

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

Regards,
-marc

Luis Machado Reis

unread,
Apr 11, 2016, 2:34:05 PM4/11/16
to jac...@googlegroups.com
Marc

So I can't use a already generated jacoco.exec file to check line coverage and I need to this before Jacoco restore instrumented classes (I instrumented them offline because PowerMock issues).

There is no way to generate a jacco.exec file containing all verifications to be analyzed later?

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/i9kHsljdFOo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/570B1ED5.4040802%40mountainminds.com.

For more options, visit https://groups.google.com/d/optout.



--

Aurea

Luis Machado Reis | Software Architect
luis...@aurea.com
Skype: luismachadoreis

www.aurea.com

Marc R. Hoffmann

unread,
Apr 11, 2016, 2:54:33 PM4/11/16
to jac...@googlegroups.com
Actually for report generation you need the original classes, not the instrumented ones. Using the latter will fail with an error message.

So, yes, you can create the report at any point later in time as long as you have exec files and the corresponding classes.

Regards,
-marc

Luis Machado Reis

unread,
Apr 11, 2016, 3:15:45 PM4/11/16
to jac...@googlegroups.com
Marc

Sorry, but I am nuttz with code sometimes ...

So I can load Jacoco.exec and run Analyzer to get detailed line coverage?


For more options, visit https://groups.google.com/d/optout.

Marc R. Hoffmann

unread,
Apr 11, 2016, 3:36:08 PM4/11/16
to jac...@googlegroups.com
Hi,

to create a JaCoCo report (aka "analyze") you need

1) uninstrumented class files used at test execution
2) dumped exec filed
3) optionally source files for highlighted reports
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/CAPKzoZ%2BhXhRUxEkqEsxSMWguGPF%2Bgzt7mmDQNDy3LzjLOg_SQg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


-- 
Marc Hoffmann
hoff...@mountainminds.com
_______________________________________________
Mountainminds GmbH & Co. KG

Nussbaumstr. 4 * 80336 Muenchen * Germany 
Phone/Fax +49-700-68664637 * 0700-MTNMINDS

Registergericht Muenchen * HRA 80201
Mountainminds Verwaltungs GmbH
Registergericht Muenchen * HRB 143183
Geschaeftsfuehrer Marc Hoffmann

Luis Machado Reis

unread,
Apr 11, 2016, 4:23:51 PM4/11/16
to jac...@googlegroups.com
Marc

Last question: when you say uninstrumented classes is only target classes .. or I need my test classess too? That is the point .. Jacoco.exec contains the result of test execution?

Thanks a lot!


For more options, visit https://groups.google.com/d/optout.

Marc R. Hoffmann

unread,
Apr 11, 2016, 4:53:43 PM4/11/16
to jac...@googlegroups.com
You only need the classes you want to create a coverage report for. Normally this is the application under test, not the test classes.

But this is all up to you: The jacoco.exec files contains execution data for all classes loaded into the JVM.

Luis Machado Reis

unread,
Apr 11, 2016, 5:09:50 PM4/11/16
to jac...@googlegroups.com
Thx man!




I will do it this night!


For more options, visit https://groups.google.com/d/optout.

Luis Machado Reis

unread,
Apr 13, 2016, 11:11:07 AM4/13/16
to jac...@googlegroups.com
Hey Marc

Just to follow-up you ... it is working

public void create() throws IOException {

execFileLoader = new ExecFileLoader();

execFileLoader.load(executionDataFile);

CoverageBuilder coverageBuilder = new CoverageBuilder();

Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);

analyzer.analyzeAll(new File(project.getClassesFolder()));


for (IClassCoverage cc : coverageBuilder.getClasses()) {

Map<String, Boolean> lines = coverageMap.get(cc.getName());

if (lines == null) {

lines = new TreeMap<String, Boolean>();

}

for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {

lines.put(Integer.toString(i), isCovered(cc.getLine(i).getStatus()));

}

ICounter lineCounter = cc.getLineCounter();

for (int i = 1; i <= lineCounter.getTotalCount(); i++) {

Boolean line = lines.get(Integer.toString(i));

if (line == null) {

lines.put(Integer.toString(i), true);

}

}

coverageMap.put(cc.getName(), lines);

}

createReport();

}


The last for loop is to set covered to static lines ... the I am getting the same coverage shown in Jacoco HTML Reports and now I can generate my JSON and merge to other JSON to get a combined number.

Thanks.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages