Functional Test Coverage using JaCoCo

2,219 views
Skip to first unread message

eajaz...@gmail.com

unread,
Dec 5, 2014, 12:54:09 PM12/5/14
to jac...@googlegroups.com
I am working on to get Functional Test Coverage using JaCoCo and SONAR for a java based application.

My Requirement:
1. Get Functional Test Coverage.
2. Publish the Functional Test Coverage results to SONAR(pass on the jacoco.exec file to SONAR)

Below is the set up I did:
1. Set up instances on my DVL(development box) and make the system up and running.

2. In the /bin directory of the instances, I am including jacoco agent in the CATALINA_OPTS variable with below configuration: vim catalina.sh export CATALINA_OPTS="$CATALINA_OPTS -javaagent:${XYZ_ROOT}/WEB-INF/lib/org.jacoco.agent-0.5.8.201206210517.jar=includes=com.xyz.xx.*,excludes=com.xyz.xx.webclient.command.UIBean,output=tcpclient,address=lxdm379m7.xyz.com,port=9000"

(lxdm379m7.xyz.com is my sonar server and 9000 is the port number)

3. Now restarted the server, And the server is up. 4. I do manual testing on my AUT which is on my DVL. Hit pages back and forth.

My Issue:
Not able to generate the jacoco.exec file.

Help I need:
1. Why is the jacoco.exec file not generated.
2. If it is generated, where can I find it? and how to pass it on to SONAR ?

Any help or clue on this is highly appreciated. I am stuck with this nightmare.

Feel free to ask me questions.

Regards
Eajaz

Marc Hoffmann

unread,
Dec 8, 2014, 2:45:58 AM12/8/14
to jac...@googlegroups.com
Hi Eajaz,

if you want the JaCoCo agent to create a exec *file* you should
configure the output to file:

output=file

Or just stick with the default (which is file). See documentation:

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

Best regards,
-marc

eajaz...@gmail.com

unread,
Dec 8, 2014, 8:25:48 PM12/8/14
to jac...@googlegroups.com
Thanks Hoffman. When I use "output=file", I just get a "jacoco.exec" of file size '0'. This is happening during the start of tomcat server. Even after hitting pages, back n forth, and shut down tomacat, I still see the jacoco.exec of size 0. Time stamp of it is the time of server start.

Can someone please help.

Sent from my iPhone
> --
> 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/brOikLgBUWo/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/8e0d16c4fb886136ad566bb097e2b234%40mountainminds.com.
> For more options, visit https://groups.google.com/d/optout.

Marc R. Hoffmann

unread,
Dec 9, 2014, 12:07:59 AM12/9/14
to jac...@googlegroups.com
The coverage data is written at the moment the JVM under test shuts
down. Make sure the tomcat server is properly shut down, not just killed.

Regards,
-marc

eajaz...@gmail.com

unread,
Dec 10, 2014, 2:17:24 PM12/10/14
to jac...@googlegroups.com
Hi Marc,
I shutdown the jvm gracefully only. Still nothing happens on the jacoco.exec. When I start the server and do "ps -ef | grep jacoco", I do see the java agent is been set :
-javaagent:/xyz/home/emahaboo/work/deployment/deployment_active/xyz/site/xyz/WEB-INF/lib/org.jacoco.agent-0.5.8.201206210517.jar=includes=com.xyz.xx.*,excludes=com.xyz.xx.webclient.command.*UIBean*,output=file,address=lxdm839m7,port=6301


-Eajaz

eajaz...@gmail.com

unread,
Dec 10, 2014, 6:46:50 PM12/10/14
to jac...@googlegroups.com, eajaz...@gmail.com
Can some please help? Been stuck with this for weeks now.

Regards
Eajaz

eajaz...@gmail.com

unread,
Dec 12, 2014, 1:22:54 PM12/12/14
to jac...@googlegroups.com, eajaz...@gmail.com
Hi Marc,

You got any clue for my issue? Been stuck.

Marc R. Hoffmann

unread,
Dec 14, 2014, 5:16:25 AM12/14/14
to jac...@googlegroups.com
What operating system are your running on? How do you shutdown tomcat?

-marc

Marc R. Hoffmann

unread,
Dec 14, 2014, 5:24:55 AM12/14/14
to jac...@googlegroups.com
If poper shutdown doesn't work for you there are two alternatives to
request a dump without shutting down tomcat:

1) Enable JMX (agent parameter jmx=true), connect to the tomcat JVM with
JConsole and execute dump on the bean org.jacoco:type=Runtime
2) Run the JaCoCo agent in tcpserver output mode (on a free port!) and
request a dump with the Ant task or Maven goal.

Regards,
-marc



On 10.12.14 20:17, eajaz...@gmail.com wrote:

eajaz...@gmail.com

unread,
Dec 15, 2014, 3:27:42 PM12/15/14
to jac...@googlegroups.com
Hi Marc,

This is the OS I am using:

LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.10 (Final)
Release: 5.10
Codename: Final


Regards
Eajaz
Message has been deleted

eajaz...@gmail.com

unread,
Dec 15, 2014, 6:01:03 PM12/15/14
to jac...@googlegroups.com
Hi Marc,
When I set this property jmx=true, I get the below error while starting the tomcat server.

export CATALINA_OPTS="$CATALINA_OPTS -javaagent:${XYZ_ROOT}/WEB-INF/lib/org.jacoco.agent-0.5.8.201206210517.jar=includes=com.xyz.xy.*,output=file,destfile=/xyz/dvl/xyz/app/int/tomcat1/reports/jacoco.exec,dumponexit=true,jmx=true,address=${XY_NODE},port=${JAC_PORT}"


Caused by: java.lang.IllegalArgumentException: Unknown agent option "jmx".
at org.jacoco.agent.rt_vy46ht.core.runtime.AgentOptions.<init>(AgentOptions.java:181)
at org.jacoco.agent.rt_vy46ht.JacocoAgent.<init>(JacocoAgent.java:62)
at org.jacoco.agent.rt_vy46ht.JacocoAgent.premain(JacocoAgent.java:158)
... 6 more
FATAL ERROR in native method: processing of -javaagent failed


I start and stop my server using this command "xyserver start, xyserver stop".

Regards
Eajaz

Marc R. Hoffmann

unread,
Dec 16, 2014, 2:00:34 AM12/16/14
to jac...@googlegroups.com
Hi Aajaz,

I think know I see the issue: You're using a quite old version of JaCoCo
(more than 2 Years old). Can you please update to to 0.7.2?

Thanks,
-marc

On 15.12.14 23:58, eajaz...@gmail.com wrote:
> Hi Marc,
>
> When I set this property jmx=true, I get the below error while starting the tomcat server.
>
> export CATALINA_OPTS="$CATALINA_OPTS -javaagent:${XYZ_ROOT}/WEB-INF/lib/org.jacoco.agent-0.5.8.201206210517.jar=includes=com.etrade.xy.*,output=file,destfile=/etrade/dvl/xyz/app/int/tomcat1/reports/jacoco.exec,dumponexit=true,jmx=true,address=${XY_NODE},port=${JAC_PORT}"
>
>
> Caused by: java.lang.IllegalArgumentException: Unknown agent option "jmx".
> at org.jacoco.agent.rt_vy46ht.core.runtime.AgentOptions.<init>(AgentOptions.java:181)
> at org.jacoco.agent.rt_vy46ht.JacocoAgent.<init>(JacocoAgent.java:62)
> at org.jacoco.agent.rt_vy46ht.JacocoAgent.premain(JacocoAgent.java:158)
> ... 6 more
> FATAL ERROR in native method: processing of -javaagent failed
>
>
> I start and stop my server using this command "etserver start, etserver stop".
>
> Regards
> Eajaz
>

eajaz...@gmail.com

unread,
Dec 16, 2014, 3:25:20 PM12/16/14
to jac...@googlegroups.com
Thanks Mark. I used the latest version of Jacoco 0.7.2. like this:

vim catalina.sh
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:${ET_AF_APP_XYZ_ROOT}/WEB-INF/lib/org.jacoco.agent-0.7.2.201409121644.jar=includes=com.xyz.ee.*,excludes=com.xyz.ee.webclient.command.*UIBean*,output=file,address=${ET_NODE},port=${JAC_PORT}"

Once I start the server, I get this weird error:

Failed to find Premain-Class manifest attribute in /xyz/home/emahaboo/work/deployment/deployment_active/eeAF/site/xyz/WEB-INF/lib/org.jacoco.agent-0.7.2.201409121644.jar
Error occurred during initialization of VM
agent library failed to init: instrument

Can you please tell me what should be fixed here?

eajaz...@gmail.com

unread,
Dec 16, 2014, 5:19:03 PM12/16/14
to jac...@googlegroups.com, eajaz...@gmail.com
Thanks Marc. JaCoCo latest version did the trick for the JMX solution. I was able to generate the jacoco.exec file with output=file with the jmx settings. I gained some confidence for me :)

Now a couple of more questions:
1. Is there anyway I could parse this jacoco.exec and view the reports?
2. I want to push this jacoco.exec to the SONAR server. I tried with output=tcpclient,address=lxdm379m7.xyz.com,port=9000. What I notice is nothing is happening on the SONAR server.

(address=lxdm379m7.xyz.com,port=9000)-> sonar server and port number


Regards
Eajaz

Marc Hoffmann

unread,
Dec 18, 2014, 4:23:10 AM12/18/14
to jac...@googlegroups.com
> 1. Is there anyway I could parse this jacoco.exec and view the reports?

Yes, you can create a report from exec files. JaCoCo comes with Ant task
and Maven goal for this. See documentation.

> 2. I want to push this jacoco.exec to the SONAR server. I tried with
> output=tcpclient,address=lxdm379m7.xyz.com,port=9000. What I notice is
> nothing is happening on the SONAR server.

This won't work: The JaCoCo tcp protocol is not compatible with http.
You need to provide the exec file to Sonar. Please visit Sonar
documentation and their mailing list for help.

Regards,
-marc

eajaz...@gmail.com

unread,
Dec 24, 2014, 2:24:23 PM12/24/14
to jac...@googlegroups.com
Thanks Mark, your inputs helped a lot.

sunny...@gmail.com

unread,
Jun 2, 2015, 6:23:02 AM6/2/15
to jac...@googlegroups.com, eajaz...@gmail.com
On Thursday, 25 December 2014 00:54:23 UTC+5:30, eajaz...@gmail.com wrote:
> Thanks Mark, your inputs helped a lot.

@eajaz,

Can you help me with the exact jmx combination you used?
I am using dropwizard jetty to deploy my service.

Evgeny Mandrikov

unread,
Jun 2, 2015, 11:43:33 AM6/2/15
to jac...@googlegroups.com, eajaz...@gmail.com, eajaz...@gmail.com
Hi Eajaz,

Option "jmx=true" has been added in version 0.6.2 ( see changelog http://www.eclemma.org/jacoco/trunk/doc/changes.html ), while you are using quite old version 0.5.8, so that upgrade to the most recent one will likely solve your issue.

shankar narayanan

unread,
Jun 4, 2015, 10:54:27 PM6/4/15
to jac...@googlegroups.com
Hi,

What did u do to over come premain-class error
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages