Automation For The People:: Hands-Off Load Testing
Automation For The People:: Hands-Off Load Testing
Automation For The People:: Hands-Off Load Testing
Use Apache JMeter with Apache Ant to run load tests frequently
Load testing is often relegated to late-cycle activities, but it doesn't need to be that way. In
this installment of Automation for the people, automation expert Paul Duvall describes how
you can discover and fix problems throughout the development cycle by creating a scheduled
integration build that runs JMeter tests.
View more content in this series
How many concurrent users can access your software system? How much data can be loaded
without performance degradation? What are your system's throughput requirements? How
often are these requirements tested? What if you could specify and validate that these load and
performance requirements are being met at least once a day? By running load tests as part of a
scheduled and automated build, you can more quickly determine how your system performs under
certain load conditions and quickly adapt to changes.
A project I once worked on established a good set of automated tests that could load test the
application while it ran multiple transactions. The problem was that the tests required some manual
tweaking, so the development team couldn't run them without human intervention. This limited
testing to times when the tester was available (usually waking hours only). In practice, testing
occurred only every couple of days not frequently enough for timely problem detection.
In this article, I explore techniques for creating automated tests using JMeter, running the tests
as part of an automated build, and scheduling the tests to run automatically every day typically
when machine usage is lower. Running the tests as part of a scheduled build lets you:
Reduce bottlenecks and errors that can occur when you depend on a single person to
configure and run the tests
Running JMeter
After downloading and extracting the JMeter ZIP file (see Resources for a link to download
JMeter), open a command prompt to the location where you extracted JMeter and type cd bin
to change to the bin directory. From the bin directory, type jmeter to open the JMeter Swing
application, shown in Figure 1:
You can use the JMeter GUI to create test plans. The different types of test plans in JMeter
include:
In Listing 1, I use Ant's taskdef task to define the JMeter task. I name it jmeter so that I can use it
elsewhere in the Ant script. To use this script you must have the ant-jmeter.jar file (see Resources
for a download link) in the Ant classpath.
The example code in Listing 2 runs a single JMeter load test, called BreweryTestPlan.jmx. To run
all of the tests in a certain directory, simply enter *.jmx in place of a specific filename. The required
attributes of the jmeter task are jmeterhome, testplan(s), and resultlog or resultlogdir. (Listing
2 doesn't show resultlogdir, because it uses resultlog.)
The Ant code in Listing 2 creates an output file called JMeterResults.xml, which is used to create
HTML reports.
JMeter also provides a less detailed XSL stylesheet file that summarizes the load tests' results.
Later in the article, I'll show you how these reports can be displayed from a CruiseControl
Continuous Integration (CI) server (see Resources).
Many other built-in parameters and properties are available for modifying how JMeter tests are run
(see Resources for more information).
Using parameters and properties gives you a certain level of flexibility in how to execute load tests,
but it doesn't address how to run load tests in different target environments, such as testing and
staging. To add environment-specific information to test plans, you need to put tokens in the .jmx
files that can be filtered and modified when the load tests run in an automated build script.
In Listing 5, an automated build is scheduled to run at 11:00 PM (2300) with CruiseControl (see
Resources). You can modify the CruiseControl configuration file to run a delegating build with a
specific Ant target, such as one named run-load-tests.
By scheduling load tests to run nightly, as in Listing 5, you won't hear excuses about workload,
vacation days, or forgetting to run the tests they just run.
Now, everyone on the team can be (literally) on the same page. Many of the other CI and build-
management servers provide similar report-integration capabilities.
Conclusion
I've demonstrated how to add automated load tests to your development toolbox. By running load
tests with the automated build and then scheduling the tests to run periodically, you can learn
about system-capacity issues long before they become a problem. This approach makes it easier
to assess the impact of architecture and data changes. When coupled with other techniques
described in this article series, it enables development teams to deliver higher-quality software
frequently.
Downloadable resources
Description Name Size
Sample Ant scripts for this article j-ap04088-jmeter-example.zip 6KB