How to perform load or performance test on REST API using Jmeter.

1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group

Number of Threads (users): The number of users that JMeter will attempt to simulate. Set the 'Number of Threads (users)' field to 10
Ramp-Up Period (in seconds): start the total number of threads. Set the 'Ramp-Up Period' field to 1
Loop Count: The number of times to execute the test. Set the 'Loop Count' field to 1.

3. Add 'HTTP request' Sampler under 'Thread Group'
Right-click on the Thread Group > Add > Sampler > HTTP request

Method - Depending on the type of method, the API was build over, select Get, Put, Post, Delete etc (in our demo we will be working on Post method)
Path: Enter your desired request which page do you want to perform load or performance test.
Set the Path field to 'http://localhost:8080/execute?command=CheckEmailAvailability'
N.B: How many Sampler do you want to add?.
It is depend on how many request do you want to perform load or performance test. For example you want to perform load or performance test for get request and you must have add 5 Sampler.
Parameters/Post Body - Add request input josn in 'Body Data'


 4. Add HTTP Header Manager under 'Sampler'
Right-click on the Sampler > Add > Configure Element > HTTP Header Manager

Click on Add button on HTTP Header Manager and add "Content-Type" under Name and "application/x-www-form-urlencoded" under Value.

5. Add 'View Results Tree' and 'Summary Report' Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report

View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self explanatory
    Avg. Bytes - average response size
   
6. Finally Save Test plan then Press 'Ctrl'+ 'R' to run Test plan



N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

No comments:

Post a Comment