Hands-on! Build your Performance Test Suite with Apache Jmeter

Begum Gezer
Beyn Technology
7 min readMay 31, 2022

--

In the previous article we talked about what is performance testing and what can we do with the Apache Jmeter. And now, we will continue with a performance test suite practice. We will talk about some useful Jmeter features to build your test plan and give examples of a few of them.

Preparing Test Scenarios

Before starting to build your test plan, the first thing you should do is brainstorm about what to include in your performance test. According to your product needs, you should decide where you want to focus on executing a performance test. For example, if you are running a performance test for the first time on your system, you should implement possible bottlenecks of the product. What is a bottleneck? It is any system resource like hardware, software, or bandwidth that defines the limits on data flow and processing limits.

Decide on your test scenarios by considering bottlenecks, or any specific case that your administrators ask for. In the second step learn the basics of the network protocol that your product uses and learn how to implement needed requests for your test scenarios.

Start with your Test Plan

Start with naming your test plan. I always think that being organized and having things in order is always good to see the journey. It will help you to know what is next and what you are exactly doing.

And you might prefer to check “Functional Testing”. If selected, it will cause JMeter to record the data returned from the server for each sample. If you have selected a file in your test listeners, this data will be written to the file. This can be useful if you are doing a small run to ensure that JMeter is configured correctly and that your server is returning the expected results. The consequence is that the file will grow huge quickly, and JMeter’s performance will suffer. This option should be off if you are doing stress testing. This option comes as off by default.

Thread Groups

We should add a thread group afterward. A thread group is the beginning of any test plan and will help us to manage Jmeter threads.

Right-click on your test plan, select “Add”, extend “Threads(Users)” on the menu, and select the “Thread Group” element. Keep the default values during test plan implementation.

We use the thread group to configure the load. As we can understand from the naming, the thread group element controls the number of threads that JMeter will use to execute your test. The controls for a thread group allow you to:

  • Set the number of threads
  • Set the ramp-up period
  • Set the number of times to execute the test

Samplers, Logic Controllers, and Config Elements

We need to add samplers in the next step. Samplers are one of the main elements to prepare a test plan. We define the requests by using samplers. In my case, I will add an HTTP Request sampler.

You can find different protocol samplers and you can add more by importing new libraries from plugin Manager on JMeter UI. You can find it under the “Options” tab. You need to enable plugin manager first if you are not able to find it in the menu.

Plugin Manager

You have to make the necessary basic configurations for the request like protocol, server name or IP address, port number, path, and of course request type for your test case. You should be giving the correct parameters, header info, and body data that is necessary for the request.

I prefer to keep repeated data with additional elements. It makes things easy if you need to change the basics for many scenarios. You can use config elements to handle repeated data like “HTTP Request Defaults” elements.

You can enter defaults like request basics and parameters. You can also use the header manager element for your requests.

We can add logic controllers to organize test plans and manage run orders. In my case, I added a “simple controller” to separate test cases. You can do more with the logic controllers and you can control workflows according to your test scenarios like adding loops or conditional controllers.

Assertions, Preprocessors, and Postprocessors

We can generate data with preprocessors and add assertions by using postprocessors. They are the most important elements to having powerful test cases in your test plan.

I commonly prefer to use BeanShell preprocessor and postprocessor, JSON extractor elements. It can change according to test plan needs. You can prefer any of those elements and also you can install new plugins like the groovy library which is one of the most popular processors.

pre-processors
post-processors

You can add an assertion in your test plan to check your request results and make sure the response is as you expected.

adding assertion

In my example, I used a JSON extractor as a post-processor. JSON extractor element helps you to extract any value from the JSON response and create or manipulate a variable with the extracted object.

You need to know path expression rules to extract a specific element in JSON response. You also need to know which object to extract like the key name.

This is a cheat sheet for JSON syntax.

The JSON response in the example is a simple json array without any inner path, so I used the “$” symbol as the path expression, and I used an index accessor as “$[random_number]” to select a random object in the response list.

The extracted variable can be used in another request or an assertion. There are a few ways to access Jmeter variables. You can use the expression ${varianle_name} to access the variable. In the above example, we extracted the variable “categories”. We use the “category” variable in the request “CategoryJoke” as a parameter.

“category” variable usage

Another way to access a Jmeter variable is using processors by calling methods for vars object. Processors use java syntax and you can use your java skills to improve your test cases.

A Jmeter variable can be accessed with method vars.get(“varible_name”) and can be manipulated via method vars.put(“variable_name”,variable_value).

Finally, add a listener to check your JMeter configurations. It helps you to view your test results. You can add a file path to extract responses from the listener.

I add a “View Result Tree” listener to check my request parameters and responses during test plan configuration. I prefer that listener since it has a simple view to me but you can prefer any of them according to your need. We will also talk about listeners and graphs later in the next articles.

“View Result Tree” listener

You can find the sample project at the following link.

I plan to continue showing how to run and configure run for the performance test plan in the next article of the Jmeter series. I hope this article guides you to build your performance test plan. Happy testing!

--

--