Efficient coverage generation for individual Junit test executions

385 views
Skip to first unread message

ashar...@gmail.com

unread,
Apr 11, 2014, 2:24:02 PM4/11/14
to jac...@googlegroups.com
Hi,

I need the unit test coverage for individual Junit tests for multiple large projects.

Right now I am using the jacoco agent on the java commandline to run individual junit tests and create exec files as per the process I read else where on this group.

However this is proving to be too slow and takes hours when for large projects compared to running EclEmma in eclipse which takes only ~30 secs for the whole suite.

I want to know if there is a more efficient way to do.

Thank,
Ashar

Marc R. Hoffmann

unread,
Apr 12, 2014, 1:17:24 PM4/12/14
to jac...@googlegroups.com
Hi Ashar,

there is, but this requires some coding or investigation with other
tools like Sonar:

JaCoCo offers a runtime API (see here:
http://www.eclemma.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/package-summary.html)

You could create your own test JUnit runner or listener which dumps
coverage data after every test through the API -- no need to launch a
new JVM n this case.

AFAIK Sonar provides such a test runner in place:
https://jira.codehaus.org/browse/SONARJAVA-94

Best regards,
-marc

ashar...@gmail.com

unread,
Apr 12, 2014, 8:07:14 PM4/12/14
to jac...@googlegroups.com
Thanks for the reply Marc,

I want to confirm what I have understood. As per my understanding I need to:

1. Run my junit execution program that executes the whole suite with the -javaagent command line argument as I am already doing.

2. After each test run, i can do either
i. Do a IAgent.dump(true) to create the exec file on disk or
ii. Do a getExecutionData(true) to get byte[].
Then get the ExecutionDataStore from the byte array by creating a
ByteArrayInputStream to then create ExecutionDataReader and setting
an instance of ExecutionDataStore as visitor through setExecutionDataVisitor.

Please let me know if this is the right way to do it. I'll give it a try the day after.

Regards,
Ashar

I can either do a dump from the

Marc R. Hoffmann

unread,
Apr 13, 2014, 4:40:40 AM4/13/14
to jac...@googlegroups.com
Hi Ashar,

correct: both ways you describe are possible, and in any case you need
configure the agent.

Note that the IAgent.dump() method will trigger a dump according to the
configured output mode. Default is writing to disc, but there are other
options e.g. for output via tcp/ip streams. See agent documentation.

How you proceed with the exec file or byte[] array (which will have the
same content) afterwards depends on what you want to archieve. A
separate report for every test? Some new kind of report?

Best regards,
-marc

Kevin

unread,
May 13, 2014, 3:32:35 PM5/13/14
to jac...@googlegroups.com, ashar...@gmail.com
Ashar,

I realize this post is about a month old, but I'm trying to do something similar to you. Which of the above approaches did you take? Did it work out how you hoped? Do you have any other advice based on what you tried?

Thanks,

//Kevin

Ashar Ghani

unread,
May 15, 2014, 8:59:17 AM5/15/14
to Kevin, jac...@googlegroups.com
Hi Kevin,

I was able to use the second approach and It worked well for me. It was also way more efficient and the whole process took me around 3 minutes for what was earlier taking hours.

Thanks again Marc!

marce...@gmail.com

unread,
Apr 8, 2015, 5:50:01 PM4/8/15
to jac...@googlegroups.com, mydataco...@gmail.com, ashar...@gmail.com
Dear Ashar,

I'm trying to do the same thing you were months ago.
Could you please send me example of your code so I can:
1) instrument a class
2) execute an associated Junit class to test the instrumented class
3) get coverage information

I'd like to do that from using java code.

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