Get Started With JMeter Part 1: Installation & Test Plans
Get Started With JMeter Part 1: Installation & Test Plans
Here you'll find the first steps for using the popular Apache JMeter testing tool.
Join the DZone community and get the full member experience.Join For Free
Container Monitoring and Management eBook: Read about the new realities of containerization.
Apache JMeter is the leading open-source tool for load and performance testing.
For those of you just getting to grips with JMeter, we’ve put together a three part ‘how to’ series on how to use this powerful tool. (Note: if you’re already a JMeter pro, you might want to take a look at this webcast on creating advanced load testing scenarios.)
This week we’ll focus on installing JMeter and creating test plans. Over the next few weeks, we’ll be tackling how to build test scripts, set up workflows, and run reports and analytics.
Step 1: How to Install JMeter
It’s important to always use the latest JMeter version. This is currently Apache JMeter 2.13 but JMeter 3.0 is expected to be released any day now, so keep checking back here for updates.
Here are the steps you should take:
- Install the latest 64-bit JRE or JDK. This is needed as JMeter is a pure Java application.
- Go to Apache JMeter and find the Binary to download to your computer.
- Once downloaded, move this file to your preferred location, extract it, and go to the folder and then the bin directory.
- Take a look at the directory. You should see a series of scripts that can run JMeter in various modes.
Congratulations! You have all you need to start working on your test plan.
Quick note: Although JMeter 2.13 has all the files you need to build and run most tests, there are some exceptions. Check out the JMeter website for more information.
Building Your First JMeter Test Plan
Launch JMeter by switching to the “bin” directory and typing the following:
- For Mac/Linux/Unix: ./jmeter.sh
- For Windows: jmeter.bat
You should now see an empty test plan (like in the image below):
Don’t see the JMeter GUI yet? Check that:
- The JAVA_HOME environment points to the JRE or JDK installation folder
- The JAVA_HOME/bin folder has been added to the PATH environment variable
What Is a Test Plan?
In your test plan, you should specify the overall settings and outline the steps that you want JMeter to execute while it runs. For your own reference, you can also name it and add comments.
Creating a Complete Test Plan
You Need To:
Set Up at Least One Thread Group and Sampler
A thread group is where you specify the number of users that you want to simulate. One thread = one user. By setting the ramp-up period, you can also tell JMeter how long it should take to reach all of the threads that you’ve chosen. You can also set the number of iterations for each user in the group with the Loop Count.
Set up Samplers
Samplers are super important as they perform the actual work in JMeter. Almost all of them generate requests for responses about your test, such as the data size, elapsed time, success/fail etc. These responses can all be viewed in the Listeners (more about that in a bit). The HTTP Request, which lets you send a HTTP or HTTPS request to a web server, is the most commonly used sampler.
We Recommend That You:
Here you can set the duration of the delay from one request to the next (i.e. how many seconds you want JMeter to wait before navigating from the homepage to the features page).
Add Configuration Elements
These allow you to manage elements, like the cache and the cookies, during the test. We recommend adding the “HTTP Cache Manager” and the “HTTP Cookie Manager” to simulate a browser’s behavior.
These let you define the pass or fail criteria for your test.
Let’s say you want to make sure your site or app responds within 100 milliseconds. You can set a Duration Assertion to specify that if any response lasts longer than 100 milliseconds, the sample will be marked as “failed.”
The most important assertion to know is the Response Assertion. This covers 99% of your needs - so no wonder it’s so popular! You can use it to test the URL, response body, messages, embedded resources, redirects, headers and more. This assertion gives you loads of flexibility as it lets you test regular expressions rather than text patterns. JMeter handles regular expressions in a very similar way to Perl - except you don’t enclose the expression in //’s.
Find out more about commonly used assertions, what they do, and how to use them in our blog post: How to Use JMeter Assertions in Three Easy Steps.
As I mentioned earlier, these let you view the results of a sampler. You can choose to view them in various formats, including a table, graph, tree, or log file. Listeners can be added anywhere in the test - but it’s important to know that they will only collect data from elements on the same level or below.
View Results Tree is the most commonly used listener as it presents all the test plan results in a user-friendly tree structure. Other listeners include the Assertion Results, Aggregate Report and Beanshell Listener.
One important thing to note: when you actually run the load tests, you should disable all your listeners as they use up a lot of memory. We’ll talk more about do’s and don’ts for running tests in the next blog post in this series.
How to Add Components to Your Test Plan
You can set up and add all of these components in the test plan before you run it. Here’s how:
- Right click on the name of your test plan.
- Select ‘Add’.
- Choose the component you want to set up and configure.
Check back next week for information on how to build test scripts, setup workflows, and run tests.
Published at DZone with permission of Clare Avieli . See the original article here.
Opinions expressed by DZone contributors are their own.