First API Test With JMeter

Measure API Performance with JMeter [Step by Step Guide]

In continuation of JMeter tutorials, our team brings amazing step by step guide on API Performance Testing with JMeter. This tutorial helps you in JMeter API test creation, configure load, execution and generate HTML report which can be published to business.

JMeter is the perfect tool for API performance measurement. JMeter have one sampler –“HTTP Request” which provides all the essential fields to configure API data – Base URL, end points, methods (GET, POST, PUT etc), body data and also provide great collections for assertions to validate API response.

This is the first tutorial on API performance testing with JMeter. Refer below for step by step guide and explanation:

Pre requisite:

Before proceeding with actual configuration following pre requisite should be done:

Once pre requisite done, you may follow below steps :

Step 1: Launch JMeter: To launch JMeter Go to J Meter bin directory and click on jmeter.bat

 

 

JMeter bin directory – click on jmeter.bat to launch JMeter
JMeter bin directory – click on jmeter.bat to launch JMeter

Step 2: Steps to Create New Test Plan:

Once JMeter open then click on File> New

JMeter Window to create Test Plan
JMeter Window to create Test Plan

 

Step 3: Now enter Test Plan name and comments

 Window to Test Plan name and comments
Window to Test Plan name and comments

 


Step 4: Right Click on Test Plan > Then click on Add then Threads (Users) and Then thread Group

  1. Right click on Test Plan
  2. Click on Add
  3. Choose Threads (Users)
  4. Click on Thread Group
JMeter window to set up Thread Group
JMeter window to set up Thread Group

Step 5:  Configure JMeter  Threads:

  1. Enter JMeter Thread Name
  2. Enter Users count
  3. Enter Ramp Time as per you test case ( you may enter 30 seconds )
Window to Configure JMeter Threads
Window to Configure JMeter Threads

Step 6:  Add Sampler:

Right click on Thread Group and then Sampler and then add HTTP Request

JMeter Sampler Window- Add HTTP Request
JMeter Sampler Window- Add HTTP Request

Step 7:  Enter API request Details: ( Refer snapshot for each fields details)

  1. Protocol: Enter protocol (http/or https) whatever support you application
  2. Enter base URI
  3. Enter end Point for request
  4. Choose Method: As per you request, you may choose Methods – POST, PUT,
  5. Body Data: You may enter Body data( JSON) in JMeter Body Data field
API request Details
API request Details

Step 8:  Add Assertions

Right click on API request and Add Assertions (Response Assertions) for API Test and add Response Assertion.

JMeter Assertions Window – Add response Assertion
JMeter Assertions Window – Add response Assertion

Step 9: Configure Assertion:

  1. Choose Main Sample Only
  2. Choose Field to Test
  3. Choose Response Code to assert status code and click on add to pattern “200” (expected response code)
  4. Choose Text Response to validate text in response

Similarly you may choose other assertions (as per you test case)

Refer below snapshot:

Response Assertion window – Assert API Response from JMeter
Response Assertion window – Assert API Response from JMeter

Choose Assertion Type and enter expected value

Choose Assertion Type and enter expected value
Choose Assertion Type and enter expected value

Step 10: Enter expected Value for Assertion

Window to add “Patterns to Test” – JMeter Assertion Window
Window to add “Patterns to Test” – JMeter Assertion Window

Step 11: Add Listeners for Report: Listeners is a component: Listeners provided by JMeter to see the results of samples:

Listeners provided by JMeter to see the results of samples

Step 12: Go to Listeners and enter the file path where you want to save JMETER execution results.

save JMETER execution results

Step 13: Run your performance Test from Run button.: As per given screenshot, click on Run button to trigger API Test with JMeter

Run your performance Test from Run button



Step14: Real time verification of JMeter API Test execution:

During test execution, you may see result of running request response. For this, go to listeners section and click on “View Results Tree” and click on Response Data and validate response.

Once execution complete, then run button will be enabled.

Real time verification of JMeter API Test execution

Step 15: Verify your performance Testing Results:  API execution report saved on your local machine (Navigate to path given in step 11) and open csv file. You will get report in CSV file.

Verify your performance Testing Results

Congratulation!! You have completed your first API Performance Test with JMeter. Hope you didn’t faced any issue still if you need any assistance feel free to write us on info@thoughtcoders.com. ThoughtCoders provides JMeter expert level training, to join our training program you may Contact Us at +919555902032.

Write A Comment