JMeter Ant Task

We all know that the word Automation means, there should not be any human intervention for the task. Similarly w.r.t Jmeter we can achieve this by integrating with the ant build process. When ever a new code is checked in and build has happened then Jmeter should kick off immediately, run the scripts and produce the performance report, So now the question is how to do this?

Answer is simple,

1.To use the task, you must have JMeter installed. You must also include ant-jmeter-1.0.9.jar in your Ant classpath. Adding the jar to $ANT_HOME/lib will make this happen automatically.

2.Set the jmeterhome parameter to your JMeter install location, and the resultlog parameter to the name of a file to log the test results to.

You can either specify a single test plan using the testplan parameter, or multiple test plans using the testplans nested element. The testplans element is a standard Ant FileSet element.

This is an Ant task for automating running JMeter test plans. The task executes one or more JMeter test plans, and logs the results to a file.

Start by defining the task to make it available to your build script:

<taskdef
name="jmeter"
classname="org.programmerplanet.ant.taskdefs.jmeter.
JMeterTask"/>

Set the jmeterhome parameter to your JMeter install location, and the resultlog parameter to the name of a file to log the test results to.

You can either specify a single test plan using the testplan parameter, or multiple test plans using the testplans nested element. The testplans element is a standard Ant FileSet element.

<jmeter
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl"/>
<jmeter
jmeterhome="c:\jakarta-jmeter-1.8.1"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
<testplans dir="${basedir}/loadtests" includes="*.jmx"/>
</jmeter>

Optional JMeter arguments supported include specifying an alternate jmeter properties file (jmeterproperties), running remote servers specified in jmeter properties file (runremote), and running the tests through a proxy or firewall (proxyhost, proxyport, proxyuser, proxypass).

Setting the failureProperty attribute will set the specified property to "true" in the event of a JMeter test failure. This gives you the opportunity to take further action such as send an email or fail the and build.

You can override JMeter properties (instead of modifying jmeter.properties) like this:

<jmeter
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
<property name="request.threads" value="1"/>
<property name="request.loop" value="10"/>
</jmeter>

You may also specify additional JVM arguments to the JVM launched to run JMeter. Here is an example of how to specify JVM arguments:

<jmeter
jmeterhome="c:\jakarta-jmeter-1.8.1"
testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
resultlog="${basedir}/loadtests/JMeterResults.jtl">
<jvmarg value="-Xincgc"/>
<jvmarg value="-Xmx128m"/>
<jvmarg value="-Dproperty=value"/>
</jmeter>

You can find XSLT file in "Jmeter\extras" folder jmeter-results-report.xsl, for generating a summary report from the result log file. The summary report is very similar to the default report created by the junitreport task. You can use the xslt task to create the report:

<xslt
in="${basedir}/loadtests/JMeterResults.jtl"
out="${basedir}/loadtests/JMeterResults.html"
style="${basedir}/loadtests/jmeter-results-report.xsl"/>

Note: If you are using JMeter 2.1 or later, you must use the new xslt stylesheet(s) included in the JMeter extras directory. The new stylesheets have been modified to support the new JMeter log file format.

If you would like failure detail messages in the report output, you must configure JMeter to output that information to the result log. To do this, set the following property in your jmeter.properties file before running the test plans:

jmeter.save.saveservice.assertion_results=all

Note: As of JMeter 1.9RC2(?), the default results output format is now csv. It must be changed to xml in order to use the xslt task to create the html report:

jmeter.save.saveservice.output_format=xml

There is also another XSLT file that was contributed which generates an enhanced report that includes expandable details.

The report will look something like this:

Parameters

AttributeDescriptionRequired
jmeterhomeJMeter install location.Yes
testplanThe location of the test plan file.Either testplan or testplans
resultlogThe location of the result log file.Either resultlog or resultlogdir
resultlogdir
The directory to place result log files. When used, result log file names will match the test plan files names, with the extension renamed from .jmx to .jtl.
Either resultlog or resultlogdir
failurepropertyThe name of a property to set to "true" in the event of a test plan failure.No
jmeterpropertiesThe location of an alternate jmeter.properties file to use.No
runremoteIf "true", runs remote servers specified in jmeter.properties. Default is "false".No
proxyhostHost name of a proxy to run the tests through.No
proxyportPort of the proxy host specified.No
proxyuserUsername of the proxy host specified.No
proxypassPassword of the proxy host specified.No

Nested Elements

ElementDescription
testplansUse instead of testplan attribute when you want to specify multiple test plan files. This element is a standard Ant FileSet element.
propertyUse to specify additional JMeter properties (instead of modifying jmeter.properties file). Attributes include name and value.
jvmargUse to specify JVM arguments to the JVM launched to run JMeter. The only attribute is value.
jmeterarg
Use to specify additional JMeter command line arguments. The only attribute is value.

Comments

  1. Hi Pramod,

    Nice article.. Its really helpful to generate such reports..
    However, have you tried adding the listeners/graphs also to the report? say, transactions per sec or response times graphs?

    ReplyDelete

Post a Comment

Popular posts from this blog

Ajax Testing with Jmeter

JDBC Testing with Jmeter

Running Junit Cases with Jmeter(Basic)