Performance Testing experience using Ant and Jmeter - Part 2

In my last blog post, i described how i have used jmeter-plugins at my current client site, now i am faced with another problem , i need to be able to run these performance test from command line, in other for these performance tests to be executed in a CI environment such as teamcity.

A quick search brings to light the ant jmeter task which is an ant task for running jmeter test. This fulfils a number of the objectives i have set in this first part of this blog post as teamcity has got an inbuilt runner for ant. To install this, you would need to include ant-jmeter-1.1.1.jar in your Ant classpath. See the link for more instructions.

And the author of the ant jmeter tasks has alsop produced an xsl file which can be fed into the xslt ant task to produce a nicely formatted html result page.

I have put all these into an ant script that looks like the below:


<project name="Performance Testing for my project" basedir="." xmlns:ac="antlib:net.sf.antcontrib"> <taskdef uri="antlib:net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml"> <classpath> <pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/> </classpath> </taskdef>

<target name="clean"> <delete includeemptydirs="true"> <fileset dir="Results" excludes="**/PerformanceCharts.html"/> </delete> </target>

<target name="run-jmeter" depends="clean"> <taskdef name="jmeter" classpath="${basedir}/jakarta-jmeter-2.5.1/extras/ant-jmeter-1.1.0.jar" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

  &lt;testplans dir=&quot;${basedir}/TestPlan&quot; includes=&quot;*.jmx&quot;/&gt;
  &lt;property name=&quot;request.threads&quot; value=&quot;300&quot;/&gt;
  &lt;property name=&quot;request.loop&quot; value=&quot;10&quot;/&gt;


<target name="create-reports" depends="run-jmeter"> <xslt in="${basedir}/Results/JMeterResults.xml" out="${basedir}/Results/JMeterResults.html" style="${basedir}/jakarta-jmeter-2.5.1/extras/jmeter-results-detail-report_21.xsl"/> </target>

<target name="create-graphs" depends="create-reports"> <ac:for param="reportType" list="TimesVsThreads,ResponseTimesOverTime,ThreadsStateOverTime"> <sequential> <java jar="${basedir}/jakarta-jmeter-2.5.1/lib/ext/CMDRunner.jar" fork="true"> <arg value="–tool"/> <arg value="Reporter"/> <arg value="–generate-png"/> <arg value="${basedir}/Results/@{reportType}.png"/> <arg value="–input-jtl"/> <arg value="${basedir}/Results/JMeterResults.xml"/> <arg value="–plugin-type"/> <arg value="@{reportType}"/> <arg value="–width"/> <arg value="800"/> <arg value="–height"/> <arg value="600"/> </java> </sequential> </ac:for> </target>

<target name="main" depends="clean,run-jmeter,create-reports,create-graphs"/> </project>


I have added an additional target for deleting the test result files as jmeter would append subsequent test results to the previous test results in the file, if file is not deleted.

You would also notice that there is a target named “create-graphs”, this uses the CMDRunner.jar which is a command line utility shipped with jmeter-plugins. This tool has helped me to re-create the graphs which i referred to in part 1 of the blog. It parses the xml result created by the ant jmeter task and creates png images for each of the graphs specified.

This graph images can then be embedded into an html page to be displayed in teamcity.

I hope this helps someone.

You Might Also Like
comments powered by Disqus