Introduction
Performance tests can be daunting for the first-timer with little to no experience. Hopefully, this blog will help you to get started.
We are going to use a simple open source API https://catfact.ninja/fact.
Catfact is one of the most popular free APIs on which a simple performance test will be done.
First Steps
We are going to need Jmeter which we can download from here.
Install/Extract when you are done. Navigate to the bin folder and then open jmeter.bat.
You should soon have a window like the one below.
The UI itself is intuitive and simplistic. You have a standard navigation tree on the left and each option on the main window. By default, the Test Plan should be opened. As the name suggests, a test plan is where you configure and run tests. Name your test plan accordingly, I am naming it Jmeter_Example.
Thread Group
Create a Thread Group by following the screenshot below.
Now, The Thread Group contains the 3 most important parameters that every performance tester should know.
- Number of Threads(users)
- Ramp-up Period(seconds)
- Loop Count
Number of Threads(users):
This represents the number of simultaneous threads that will be doing an action/ calling an API. Each thread is independent of another and every step in the test plan gets executed separately in them. This is just equivalent to how each user needs to log in independently inside their application.
Ramp-up Period(seconds)
Imagine the number of threads being 5. It does a little extra good to start the users from 1 and then ramp it up to 5. This enables us to validate the performance of the test app with different thread counts. If you set your Ramp-up period to 1, then after 1s, the Jmeter increases the number of threads to 2 and then so on till the number reaches 5.
Loop Count:
It is the number of times you want to test to be executed. It is detached from ramp-up and number of threads. For example, it will keep looping even if the requests are already sent.
Adding a New HTTP Request
Since we are testing an API, the most obvious step is to add an HTTP Request. Right Click on the Thread Group ➡️ Click on Add ➡️ Sampler ➡️ HTTP Request
The next step is to fill in the HTTP request details. For the above example, let us bisect the URL to separate sensible parts which are the base URL/server name and the endpoint/path.
Filling these details in the respective fields will set up the request we want to test.
Your HTTP Request must look like the one below.
Setting up for Results
Once you have reached this point, you can just run the test. But there is no easy way to debug unless we add a few specific Samplers to our test. One such would be the “View Results Tree”.
You can add this by Right Click on the Thread Group ➡️ Click on Add ➡️ Listener ➡️ View Results Tree
Now click on the “Green Play” button at the Toolbar runs the test.
Once you click on it, wait for the test to finish and then click on the View Results Tree in the navigation tree on the left.
In the main window, you should be able to see the Result, the request sent and then the Response data. When you click on the Response, you should see a fact about the cats, like below.
Setting final things up
Now, let us go to the thread group and change the Loop count to 100. Then, run this test. The View Results Tree is going to be filled with individual responses.
Increase the loop count depending on the requirement to run your API tests.
Setting up a Simple Report
So, how to get quantifiable results from Jmeter? It is as simple as adding a new listener to it. Right Click on the Thread Group ➡️ Click on Add ➡️ Listener ➡️ Aggregate Report.
The Aggregate report contains the most critical Key Performance Indicators(KPI) of the test. I have attached a screenshot of it below.
Each of the columns is an important KPI. But for now, let us look at the average. It’s value represents the value of the average response of all the requests that we configured. For any API performance test, this is the single most important indicator.
Additionally, you can also add a Response time graph from the Listeners to get a graph like the one below.
With this, you have successfully run your first performance test. Thanks for reading, watch out for more blogs that cover more than just the basics of performance tests.