jenkins the definitive guide

(Jeff_L) #1

your application, as well as random pauses, conditions and loops, and other variations designed to better
imitate real user actions.


JMeter runs as a Swing application, in which you can configure your test scripts (see Figure 6.24,
“Preparing a performance test script in JMeter”). You can even run JMeter as a proxy, and then
manipulate your application in an ordinary browser to prepare an initial version of your test script.


A full tutorial on using JMeter is beyond the scope of this book. However, it is fairly easy to learn, and
you can find ample details about how to use it on the JMeter website. With a little work, you can have
a very respectable test script up and running in a matter of hours.


What we are interested in here is the process of automating these performance tests. There are several
ways to integrate JMeter tests into your Jenkins build process. Although at the time of writing, there
was no official JMeter plugin for Maven available in the Maven repositories, there is an Ant plugin. So
the simplest approach is to write an Ant script to run your performance tests, and then either call this
Ant script directly, or (if you are using a Maven project, and want to run JMeter through Maven) use
the Maven Ant integration to invoke the Ant script from within Maven. A simple Ant script running
some JMeter tests is illustrated here:


<project default="jmeter">
<path id="jmeter.lib.path">
<pathelement location="/Users/johnsmart/Projects/Books/jenkins-the-definitive-guide/hudsonbook-content/tools/jmeter/extras/ant-jmeter-1.0.9.jar"/>
</path>

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

<target name="jmeter">
<jmeter jmeterhome="/Users/johnsmart/Projects/Books/jenkins-the-definitive-guide/hudsonbook-content/tools/jmeter"
testplan="/Users/johnsmart/Projects/Books/jenkins-the-definitive-guide/hudsonbook-content/src/test/jmeter/gameoflife.jmx"
resultlog="/Users/johnsmart/Projects/Books/jenkins-the-definitive-guide/hudsonbook-content/target/jmeter-results.jtl">
<jvmarg value="-Xmx512m" />
</jmeter>
</target>
</project>

This assumes that the JMeter installation is available in the tools directory of your project. Placing
tools such as JMeter within your project structure is a good habit, as it makes your build scripts more
portable and easier to run on any machine, which is precisely what we need to run them on Jenkins.

Free download pdf