JaCoCo coverage ANT task

1,264 views
Skip to first unread message

Colm Harrington

unread,
Dec 28, 2012, 7:11:34 AM12/28/12
to jac...@googlegroups.com
Hi Guys,

I'm trying to use ANT to run my tests and collect coverage data. I can do the process 'manually' but now I want to automate it.
I've modified the build.xml available at:


Basically I want to call the test target and, instead of running the example program via 'java', I want to call jMeter to run my tests by using something like this:

<!-- Define the jMeter task to make it available to the build script -->
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<!-- Create target to start Tomcat (as a service) -->
<target name="tomcat-start">
<echo>Starting Tomcat</echo>
<exec executable="net">
<arg value="start" />
<arg value="${tomcat.service.name}" />
</exec>
</target>

<!-- Create target to stop Tomcat (as a service) -->
<target name="tomcat-stop">
<echo>Stopping Tomcat</echo>
<exec executable="net">
<arg value="stop" />
<arg value="${tomcat.service.name}" />
</exec>
</target>



<target name="test"> <!-- depends="compile"> -->
 
 
<!-- Call target to start Tomcat (as a service) -->
 
<!-- <antcall target=”tomcat-start”/> -->
 
 
<!-- Wrap test execution with the JaCoCo coverage task -->
 
<jacoco:coverage destfile="${result.exec.file}">
 
<!-- <java classname="org.jacoco.examples.parser.Main" fork="true">
 <classpath path="${result.classes.dir}" />
 <arg value="2 * 3 + 4"/>
 <arg value="2 + 3 * 4"/>
 <arg value="(2 + 3) * 4"/>
 <arg value="2 * 2 * 2 * 2"/>
 <arg value="1 + 2 + 3 + 4"/>
 <arg value="2 * 3 + 2 * 5"/>
 </java> -->

 
 
<jmeter jmeterhome="C:\jmeter\apache-jmeter-2.7"
 
testplan="C:\jmeter\apache-jmeter-2.7\tests\auto.jmx"
 
resultlog="C:\jmeter\apache-jmeter-2.7\results\coverageTestResults.jtl" />
 
 
</jacoco:coverage>
 
 
<!-- Create target to stop Tomcat (as a service) -->
 
<!-- <antcall target=”tomcat-stop”/> -->
 
 
</target>

When I run 'ant test' at the command line, I get an error: 

BUILD FAILED
C:\...\build.xml:70: jmeter is not a valid child of the coverage task

Is there some way I can do this ?

Thanks,
Colm

Marc R. Hoffmann

unread,
Dec 28, 2012, 7:23:58 AM12/28/12
to jac...@googlegroups.com
Hi,

in your scenario the code under test is not jmeter but the code deployed
to tomcat, right? So you will need to configure tomcat to run under code
coverage not jmeter.

Here are the steps:

1) Start your tomcat configured with this agent as a VM parameter,
typically you will set the environment variable JAVA_OPTS. Use the
output=tcpserver, find all agent options and syntax here
http://www.eclemma.org/jacoco/trunk/doc/agent.html
2) After your tests have finished and before you stop tomcat you dump
execution data from the server with the dump Ant task.
3) Proceed with report generation based on the dumped *.exec file.

Best regards,
-marc
> <targetname="test"><!-- depends="compile"> -->
>
> <!-- Call target to start Tomcat (as a service) -->
> <!-- <antcall target=�tomcat-start�/> -->
>
> <!-- Wrap test execution with the JaCoCo coverage task -->
> <jacoco:coveragedestfile="${result.exec.file}">
> <!-- <java classname="org.jacoco.examples.parser.Main" fork="true">
> <classpath path="${result.classes.dir}" />
> <arg value="2 * 3 + 4"/>
> <arg value="2 + 3 * 4"/>
> <arg value="(2 + 3) * 4"/>
> <arg value="2 * 2 * 2 * 2"/>
> <arg value="1 + 2 + 3 + 4"/>
> <arg value="2 * 3 + 2 * 5"/>
> </java> -->
>
> <jmeterjmeterhome="C:\jmeter\apache-jmeter-2.7"
> testplan="C:\jmeter\apache-jmeter-2.7\tests\auto.jmx"
> resultlog="C:\jmeter\apache-jmeter-2.7\results\coverageTestResults.jtl"/>
>
> </jacoco:coverage>
>
> <!-- Create target to stop Tomcat (as a service) -->
> <!-- <antcall target=�tomcat-stop�/> -->
>
> </target>
> |
>
> When I run 'ant test' at the command line, I get an error:
>
> BUILD FAILED
> C:\...\build.xml:70: jmeter is not a valid child of the coverage task
>
> Is there some way I can do this ?
>
> Thanks,
> Colm
>
> --
>
>


--
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

Colm Harrington

unread,
Dec 28, 2012, 8:48:26 AM12/28/12
to jac...@googlegroups.com
Hi Marc,

Thanks for your quick reply.

I have set the JAVA_OPTS variable in the startup.bat file as follows:

set JACOCO=-javaagent:C:\dev\servers\jacocoagent.jar=destfile=C:\dev\jacoco.exec,append=true,output=tcpserver,address=10.xxx.xxx.xxx,port=6300
set JAVA_OPTS=%JAVA_OPTS% %JACOCO%

However, I don't understand where the jMeter tests get run in the scenario you outlined above. In step 2 above you say "after the tests ..." but I don't see where they get kicked off. Should I include a call to jMeter in something like this ? but i think coverage can only have 1 child !

<jacoco:coverage destfile="${result.exec.file}">

                       <antcall target=”tomcat-start”/>
<jmeter jmeterhome="C:\jmeter\apache-jmeter-2.7"
testplan="C:\jmeter\apache-jmeter-2.7\tests\auto.jmx"
resultlog="C:\jmeter\apache-jmeter-2.7\results\coverageTestResults.jtl" />
                        
                        <jacoco:dump address="localhost" reset="true" destfile="c:\remote.exec"/>

                        <antcall target=”tomcat-stop”/>
</jacoco:coverage>

Thank you for your patience with me, I really appreciate it ...

/
Colm

Marc R. Hoffmann

unread,
Dec 28, 2012, 8:54:19 AM12/28/12
to jac...@googlegroups.com
Hi Colm,

it looks good, except that the jacoco:coverage tag should not be there
any more. Also I'm not sure if the address option of the agent is
correct. If everything runs on the same machine you can drop this option
and the agent will automatically bind to localhost.

Best regards,
-marc





On 28.12.12 14:48, Colm Harrington wrote:
> Hi Marc,
>
> Thanks for your quick reply.
>
> I have set the JAVA_OPTS variable in the startup.bat file as follows:
>
> set
> JACOCO=-javaagent:C:\dev\servers\jacocoagent.jar=destfile=C:\dev\jacoco.exec,append=true,output=tcpserver,address=10.xxx.xxx.xxx,port=6300
> set JAVA_OPTS=%JAVA_OPTS% %JACOCO%
>
> However, I don't understand where the jMeter tests get run in the
> scenario you outlined above. In step 2 above you say "after the tests
> ..." but I don't see where they get kicked off. Should I include a call
> to jMeter in something like this ? but i think coverage can only have 1
> child !
>
> |
> <jacoco:coverage destfile="${result.exec.file}">
>
> <antcall target=�tomcat-start�/>
> <jmeter jmeterhome="C:\jmeter\apache-jmeter-2.7"
> testplan="C:\jmeter\apache-jmeter-2.7\tests\auto.jmx"
> resultlog="C:\jmeter\apache-jmeter-2.7\results\coverageTestResults.jtl" />
>
> <jacoco:dumpaddress="localhost"reset="true"destfile="c:\remote.exec"/>
>
> <antcall target=�tomcat-stop�/>
> > <arg value="${tomcat.service.name <http://tomcat.service.name>}" />
> > </exec>
> > </target>
> >
> > <!-- Create target to stop Tomcat (as a service) -->
> > <target name="tomcat-stop">
> > <echo>Stopping Tomcat</echo>
> > <exec executable="net">
> > <arg value="stop" />
> > <arg value="${tomcat.service.name <http://tomcat.service.name>}" />
> hoff...@mountainminds.com <javascript:>

Colm Harrington

unread,
Dec 28, 2012, 10:43:06 AM12/28/12
to jac...@googlegroups.com
Great, It works !!

Thanks for your help, Marc.

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