How to use JMeter for API Load Testing? – Devstringx

Back to Blog
Banner on Jmeter API load Testing

How to use JMeter for API Load Testing? – Devstringx

Jmeter API Testing 

Jmeter Api Testing is better understood as a kind of Performance testing that is used to test the behavior of a software application when a heavy load is applied to it. The type of software testing is categorized under Non-Functional testing.

Now Let’s Understand About JMeter and its Working

The Apache JMeter is the Java Open-Source Tool that analyses and measures the performance of web applications. The Working of JMeter can be best described by the following diagram.

Jmeter Explanation

Installation of Jmeter

  • Run JMeter executable in bin/ folder. Executable extensions depend on OS (.bat for Windows, .sh for Linux / Mac)
  • The JMeter will be launched!!

Now Let’s Understand What is an API?

API can be better understood as an Application Programming interface. It provides interaction between the two applications.

  • JMeter Components

All Major components of JMeter load testing are provided in the flow diagram given below:-

Jmeter major components

1) Test Plan

A test plan can be viewed as a JMeter script to run tests. A test plan consists of test elements such as thread groups, logic controllers, listeners, timers, assertions, and configuration elements.

2) Thread Group

It describes the number of threads JMeter will use during the test.

Steps to add Thread Group- Right Click on Test Plan>> Hover over Threads (Users)>> Click Thread Group

Configuration in Control Panel

Configurations in a Thread Group Control Panel

  • Name– Assigns Name to Thread Group
  • Comments– It is an optional textbox, that should contain the description of the action performed by the Thread Group

Thread Properties

  • Number of Threads–It is the count of the number of virtual users that we want to connect to the server.
  • Ramp-Up Period–This is the time in which JMeter can bring the number of threads into the running state.
  • Loop Count– It indicates how many times each thread is supposed to perform the task.
  • Loop Count Forever– When checked, it disables the loop count value and causes the loop to run infinitely until manually stopped.
  • Delay Thread Creation until needed– It is used to delay the thread creation until a value is specified in this field (in seconds).
  • Scheduler– When checked, the scheduler configurations are enabled and considered for scheduling tests at a particular time.

Recommended to Read- How to Create Test Plan Using Jmeter?

Configurations in the Action to be Taken After a Sampler Error

  • Continue– In case of a sampler error the test should be continued.
  • Start Next Thread Loop– It continues the test with the next thread execution.
  • Stop Thread– In case of error, the current thread gets stopped
  • Stop Test– The thread is stopped gracefully after completing the current sampler request.
  • Stop Test Now– The thread stops abruptly in case of any error.

Configurations in the “Scheduler Configuration” block

  • Duration(seconds)– It specifies the duration of the test, once reached the test stops.
  • Start-up delay(seconds)–JMeter will wait for the start-up delay specified on running a Test Script,
  • Start Time– It specifies an absolute value of system time for starting the test, once the test is run. If the above ‘Duration’ field is empty so only in this condition we can consider it.
  • End Time–It specifies an absolute value of system time for ending the test. If the above ‘Duration’ field is empty so only in this condition we can consider it.

3) Samplers:- Samplers are the components that allow JMeter to send specific types of requests to a server. They are added to the test plan to let JMeter know what type of request needs to go to a server. Requests can be HTTP, HTTP(s), FTP, TCP, SMTP, SOAP, etc.

Steps to add Sampler – Right Click on Thread Group >> Hover over Add >> Hover Over Sampler >> Click on the required Sampler

4) Logic Controllers:- They are used to define the sequence in which the requests are sent to the server.

Steps to launch a Logic Controller – Right Click on Thread Group >> Hover over Add >> Hover Over Logic Controllers >> Click on the required Logic Controllers

5) Config Element:- are used to configure or modify the sampler requests made to the server.

Steps To Add Config Element – Right-Click on either of Test Plan/Thread Group/Logic Controller >> Hover over Add >> Hover Over Config Element >> Click on the required Config Element

6) Listeners:- are the test plan elements to analyze the performance in tabular or graphical form

Steps to Add Listener – Right Click on Test plan >> Hover over Add >> Hover Over Listener >> Click on the required Listener

7) Assertions:-Assertions in JMeter are the test plan elements that are used to validate the response received from the server for a particular sampler request.

Steps To Add Assertion – Right Click on a Sampler Request >> Hover over Add >> Hover Over Assertion >> Click on the required Assertion

8) Pre-processors:- A Pre-Processor element is executed just before the request made by the sampler.

Steps To Add Pre-Processor – Right Click on either of Thread Group/Logic Controller >> Hover over ‘Add’ >> Hover Over ‘Pre-Processors>> Click on the required Pre-Processor Element

9) Post-Processors: –A Post-processor is used to process the response data, so it is executed after a sample request is made.

Steps To Add Pre-Processor – Right Click on either of Thread Group/Logic Controller>> Hover over ‘Add’ >> Hover Over ‘Post Processors’ >> Click on the required Post Processor Element

10) Timers: – This is used to pause the execution of a test for a certain specified amount of time.

Steps to Add Timers: – Right Click on Thread Group >> Hover over Add >> Hover Over Timer >> Click on the required Timer

Recommended to Read- Difference B/W Jmeter vs Loadrunner

API Load Testing Using JMeter

Let’s take an Example –

Suppose we have to test the load for 100 users who can concurrently use the API /API/getBusinessTypes for getting requests to fetch the total number of business types

Steps

  • Go to the Apache JMeter folder >> bin folder >> open the batch file>>select the Test Plan.
  • Next, Right click on the Test Plan and add a Thread Group.

  • Now Provide the number of Threads, ramp-up time, and loop. In the Provided example we have used 100 threads (users) with a ramp-up time of 50 seconds and a loop is 1

used thread

  • Right-click on Thread Group and select Samplerand to add HTTP Request and provide the details for IP, Request Type, and Path
  • Now Add the Listeners to View the Load Report. In the Provided Example we have used 2 Listeners named – Summary Report and View Result tree
  • Now Execute the API Request from The RUN button in the Toolbar

Results

  • Summary Report

Summary Report

  • View Result Tree

If you are interested in even more software testing-related articles and information from us here at Devstringx, then we have a lot to choose from

Share this post

Back to Blog