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

    <jmeter
            jmeterhome="${basedir}/jakarta-jmeter-2.5.1"
            resultlog="${basedir}/Results/JMeterResults.xml">
      <testplans dir="${basedir}/TestPlan" includes="*.jmx"/>
      <property name="request.threads" value="300"/>
      <property name="request.loop" value="10"/>
    </jmeter>
  </target>

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

Advertisements
This entry was posted in Software Testing and tagged , , , . Bookmark the permalink.

7 Responses to Performance Testing experience using Ant and Jmeter – Part 2

  1. prabhu says:

    Really a use full post.. Thanks..

  2. Alex says:

    Thanks,
    How to include that into TeamCity?

    • Since you have ant script running your test,all you need to do next is to create a build configuration in team city and then use ant as the runner.

      Its pretty easy to get this done

  3. Ravi (UK) says:

    Excellent. Thanks for this idea. I spent 5 hours trying to find a solution, this satisifies more or less what I want. I hope TeamCity provides option to break the build if JMeter fails the threshold.

  4. shurupus says:

    Realy useful post, thanks! Can you tell me the way how to move report to the teamcity? With graphsm, tables, etc?

  5. glinius says:

    Thanks for useful guide. I’d recommend to take a look at 5 Ways To Launch a JMeter Test without Using the JMeter GUI post which also covers command-line and Maven integrations and highlights how to execute existing JMeter test from Java code.

  6. Pingback: Performance Testing experience using Ant and Jmeter – Part 1 | samueladesoga

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s