Introduction to JMeter and API Testing

Kaveri B
nonstopio
Published in
5 min readMay 3, 2021

--

API is an Application Programming Interface, it works as an intermediate. Eg- if a client sends a particular request to the server and the server responds back according to your requirements.

API basically works as an intermediate or a gateway between the client and the server. so this information carried to the server through an API. To test API in order to know that if it's performing the job perfectly, if it's actually getting the right information.

With the help of JMeter, we can do the API testing and you can also see how much load your API can handle. JMeter is the performance testing tool. It is used as a load testing tool for analyzing and measuring the performance of a variety of services.

Performance Testing: Verify whether the product meets expected or required performance. It focuses on Speed, Stability, and Scalability.

Advantages of JMeter

  • Open-source & built-in java platform and platform-independent & user friendly.
  • JMeter has a comprehensive GUI which helps to create a test plan & configure the element.
  • JMeter supports scripting but it is not necessary because you can run a complete load test without knowing a bit of code, JMeter stores its test plan in XML format.
  • JMeter supports protocols such as HTTP, JDBC, FTP.
  • JMeter allows users to record HTTP or HTTPS to create a test plan using a recording facility.
  • JMeter support dashboard report generation which helps the user to understand performance test execution result.

Installation of JMeter

Before installing JMeter you must ensure that you already have java installed on your system.

The Apache JMeter looks like this

This is our home window & you can see 2 sections here.

  • Left side Frame- Consist of all the Elements of Jmeter
  • Right side Frame- Consist of the configuration

Test Plan :

The test plan is like a container that will contain all your test plans that you will need to perform. Samplers, Listeners come under the Test plan.

Right-click on Test plan & here you can see a lot of elements that we can add here. so, one of the most important is the Thread group.

Elements of JMeter

  1. Thread Groups
  2. Sampler
  3. Listener
  4. Configuration
  5. Thread Groups:-

Thread Groups is a collection of threads. Each thread represents the one user using the Application under the test. basically, each thread simulates one real user request to the server & the controls for a thread group allows you to set the number of threads

2. Samplers:-

JMeter supports HTTP, FTP, JDBC, and many other Protocols. Sampler helps the thread group know which type of request it needs to make.

HTTP request- Let's you can send HTTP or HTTPS to a Web browser.

JMeter sends an HTTP and HTTPS request to google website & retrieve HTML files or image from this website

JDBC- Sampler lets you execute database performance testing.

3. Listener:-

Listeners show the result of test execution in different format trees, tables, graphs, or log files.

Tree- shows the result of the user request in basic HTML format

Table-summery of a test result in table format.

4. Configuration:-

It sets the default variable for later use by the sampler.

Suppose we want to test a website for 100 users signing in with different credentials you did not need to record the script 100 times, you can parameterize the script to enter different login credentials.

Jmeter allows reading different parameters from a text file.

HTTP Cookie Manager — It automatically stores that cookie and will use it for all future requests to that particular website.

HTTP Request defaults — This element lets you set default values that HTTP request controllers use.

Eg- We are sending 5 HTTP requests to the server google.com, you would have to manually enter a server name=google.com for all these 5 requests instead you could add HTTP defaults with server name or IP field.

API Testing

Inside our Test plan, we need to create a Thread group, here we have Thread-Group and the number of threads or users as 5(Five). All the users are sending the request to the server at the same time so the Ramp-up period is one. and then Loop Count is two. now once you have added the thread group.

The next step is to add a sampler that is the HTTP request. now we can put Rest API and Soap API all together in the HTTP request. In the HTTP request, we can provide the server name, path along with parameters on which we performing the API testing so we can just get an API, collect the server name of that particular API provide the Path and also involve the parameter.

To get all the number of users, The protocol is HTTPS protocol for HTTPS we will be using 443 port number, The server URL is reqres.in , The method is Get method. we have set our HTTPS request, where we have provided the server name, also the path it gets into along with the parameters

For capturing the request go to thread group right click on it click on Add Listener, Click on view result in a tree, so we can view result in Tree format.

Before running the test first, save this file in the bin folder. The extension for Jmeter is .jmx.

here, we have 10 HTTP Request Because in our Theard Group we have written the Number of Users as Five, and Loop Count is Two. In HTTP request we can see thread name and other details, we can see Load Time, connect time, and size, The response code is 200, and the Response message is OK, In response data, we can see the exact data we have taken in our APIs. Code 200 represents the test has been completed Successfully.

Increasing the number of threads means increasing the load on APIs, So we can check that how much load it handles.

Conclusion:

In this way, we can test our APIs in JMeter.

--

--