Reading Score Earn Points & Engage
Science fiction

SOFTWARE TESTING

software testing

May 30, 2025  |   6 min read

G

GAUTAM
SOFTWARE TESTING
0
0
Share


API stands for Application Programming Interface.

API is a defined set of rules, which contains clearly defined methods of communication. API helps different software components to interact with each other.

API testing involves testing the collection of APIs and checking if they meet expectations for functionality, reliability, performance, and security and returns the correct response.

API testing is used to determine whether the output is well-structured and useful to another application or not, checks the response on basis of input (request) parameter, and checks how much time the API is taking to retrieve and authorise the data too.

Postman is an application for testing APIs, by sending request to the web server and getting the response back.

It allows users to set up all the headers and cookies the API expects, and checks the response.

Productivity can be increased using some of the Postman features, which are listed below.

A test in Postman is fundamentally a JavaScript code, which run after a request is sent and a response has been received from the server.

Installing Postman

One can download Postman Native App from below URL:

Download Postman

Postman is the complete toolchain for API developers, used by more than 3 million developers and 30,000 companies?

www.getpostman.com

OR one can add it from Google Chrome web store, one can get the Postman extension by clicking on below link:

https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en

POSTMAN is very easy to use. It provides collection of API calls, and one has to follow that collection of API calls for testing APIs of application.

One can select API call method from the given dropdown list, set Authorisation, Header, Body information according to the API call.

API call methods available in Postman:

API call methods available in Postman

Header according to the API call:

Header according to the API call

Body information according to the API call:

Body information according to the API call

Then, one can perform the API call by clicking Send button.

Environment Variables in Postman

One can set the environments variable, from top-right corner, according to the requirement. One can easily set environment variable by following below steps:

Click on Manage Environment from Settings (icon available at top right corner).

Click on ADD button.

Write down the Name of the Environment.

Fill key & value, which can be used as variable in collection later.

Defining Environment Variables

Add Collection:

One can add Each API call in collection and create a collection, that will be reusable for application.

Adding Collection

One can import collection of others and can export their collection, so that others can use it on their machine as well.

Import Collection

Export Collection

In API calls, I have mainly used two things:

1. HTTP Request - Request is the simplest way possible to make http calls.

HTTP Request contains of Request Method, Request URL, Request Headers, Request Body, Pre-request Script and Tests.

Request Methods - Request methods defines the type of request to be made.Request Methods available in Postman are as below:

Request Methods

I have used mainly four request methods frequently, which are as below:

POST Request - For Creating Or Updating data,

PUT Request - For Updating data,

GET Request - For Retrieving/Fetching data and

DELETE Request - For Deleting data.

Request URL - It is where to make the http request.

Request Headers - In request headers it contains key-value of the application. I have used mainly two key-value, which are as follows:

Content-Type - A content-type describes the format of object data. Content-type, which I have used the most for the requests and responses is application/json.

Authorization - An authorization token, included with requests, is used to identify the requester.

Request Body - It contains the data, if any (depends on type of request method), to be sent with request. I have used raw form of data for sending request. Example is as below:

Request Body

Pre-request Script - Pre-request scripts are piece of code that are executed before the request is sent.

Example: In order to use Postman BDD (explained later in the article) with request, one needs to define the below code in Pre-request Script.

Pre-request Script

If the environment variable for "postman_bdd_path" is not set, then request, where pre-request script is defined, will use it from the request.

Tests in Postman - In Postman one can write and run tests for each request using the JavaScript language. Below is the example:

Example of Test Description:

Test Description

Example of Test Script:

Test Script

Example of Test Result:

Test Result

2. HTTP Response - On sending request, API sends the response which consists of the Body, Cookies, Headers, Tests, Status code, and API Response Time.

Postman organises body and headers in different tabs. The status code with the time taken to complete the API call is displayed in another tab.

There are many status code, from which we can verify the response.

Few of them are mentioned below:

200 - For Successful request.

201 - For successful request and data was created.

204 - For Empty Response.

400 - For Bad Request. The request could not be understood or was missing any required parameters.

401 - For Unauthorized access. Authentication failed or user does not have permissions for the requested operation.

403 - For Forbidden, Access denied.

404 - For data not found.

405 - For Method Not Allowed or Requested method is not supported.

500 - For Internal Server Error.

503 - For Service Unavailable.

Test Scripts in Postman

With Postman one can write and run tests for each request using the JavaScript language. Code added under the Tests tab will be executed after response is received.

As shown in above example,

tests["Status code is 200"] = responseCode.code ===200;

will check whether the response code received is 200.

You can have as many tests as you want for a request. Most tests are as simple and one liner JavaScript statements. Below are some more examples for the same.

Check if response body contains a string:

tests["Body matches string"] = responseBody.has("string_you_want_to_search");

Check if response body is equal to a particular string:

tests["Body is correct"] = responseBody === "response_body_string";

Check for a JSON value:

var data = JSON.parse(responseBody);

tests["Your test name"] = data.value === 100;

Check for Response time is less than 200ms:

tests["Response time is less than 200ms"] = responseTime < 200;

Check for Successful POST request status code:

tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;

Check for Response header content type:

tests['The Content-Type is JSON'] = postman.getResponseHeader('Content-Type') === 'application/json';

Overview of Postman Behavior Driven Development (Postman BDD)

Postman BDD allows to use BDD syntax to structure tests and fluent Chai-JS syntax to write assertions. So the above test cases could look like as below:

Check for Response header content type:

it('should return JSON', () => {

response.should.be.json;

response.should.have.header('Content-Type', 'application/json');

response.type.should.equal('application/json');

});

Check for Status code is 200:

it('should be a 200 response', () => {

response.should.have.status(200); });

Check for Response time is less than 200ms:

it('should respond in a timely manner', () => {

response.time.should.be.below(200);

});

Check for Response body message should be 'User logged in successfully.':

it('message should contain', () => {

response.body.message.should.equal('User logged in successfully.') ;

});

Features & Benefits of Postman BDD

Easy syntax

It has easy syntax which makes the tests easier to write and read.

Error Handling

If error in script occurs, only that one test fails, and other tests still run. Error gets displayed for the failed script.

Lots of Assertions

It gives full access to all Chai-JS and Chai-HTTP assertions and some custom assertions for API. Assertions made easier to remember and readable such as a custom assertion as response.body.should.be.a.user

JSON Schema Validation

User can validate responses again a specific JSON schema by using assertion as response.body.should.have.schema(someJsonSchema)

Postman BDD Installation

There are two simple steps to installing Postman BDD:

1. Download Postman BDD

Create a GET request in Postman with the following URL:

http://bigstickcarpet.com/postman-bdd/dist/postman-bdd.min.js

2. Install Postman BDD

User has to add the following code in the request created as above, in Tests tab:

postman.setGlobalVariable('postmanBDD', responseBody);

Then Postman BDD will be installed globally. One can use it in any Postman request by loading the script as below:

eval(globals.postmanBDD);

Conclusion

This is how I found Postman useful for API Testing and Postman BDD made my task much easier and faster.

API

Hasnah

Written by Hasnah

7 followers



43 following

Hello

Responses (2)

Write a response

What are your thoughts?

Neha

Neha

Oct 18, 2024

Simple and Best Explanation..

Dave Park

Dave Park

Aug 4, 2022

Nice tutorial, thanks for posting it.

More from Hasnah

API

Hasnah

Hasnah

API

https://www.youtube.com/watch?v=Qlvbc6kIBOk

Feb 27, 2019

1

For my own documenta

Hasnah

Hasnah

For my own documenta

https://docs.api.getpostman.com/?_ga=2.77872916.1611962871.1551178657-269785863.1550132202#authentication

Feb 26, 2019

See all from Hasnah

Recommended from Medium

Generate REST API Documentation for Spring Boot Project Using Swagger

Javarevisited

In

Javarevisited

by

Ramesh Fadatare

Generate REST API Documentation for Spring Boot Project Using Swagger

Learn to generate REST API documentation in Spring Boot app using Swagger. This is step-by-step guide for easy setup and customize the doc.

Feb 6

3

1

How to Test LLM-Based Chatbots (with Python & Postman Templates)

Bisma Latif

Bisma Latif

How to Test LLM-Based Chatbots (with Python & Postman Templates)

LLM-powered chatbots are increasingly being integrated into user-facing applications? - ?from customer service assistants to personal?

Apr 8

4

Tutorial: Step by Step Implement Continuous Testing with Playwright: Part 5: Gain Productivity

Courtney Zhan

Courtney Zhan

Tutorial: Step by Step Implement Continuous Testing with Playwright: Part 5: Gain Productivity

Shortcuts and Tips and Tricks to Increase your Productivity when Writing & Debugging Playwright Scripts

May 4

51

This new IDE from Google is an absolute game changer

Coding Beauty

In

Coding Beauty

by

Tari Ibaba

This new IDE from Google is an absolute game changer

This new IDE from Google is seriously revolutionary.

Mar 12

5.8K

338

Top 10 GitHub Repositories for Software Testers!!

Mohammad Faisal Khatri

Mohammad Faisal Khatri

Top 10 GitHub Repositories for Software Testers!!

Top 10 GitHub repositories for Software Testers for enhancing and upgrading their skills. Check out and upgrade today!

Dec 10, 2024

10

Browser-Use Explained: The Open-Source AI Agent That Automates the Web

Browser-Use Explained: The Open-Source AI Agent That Automates the Web

Imagine spending hours chasing the perfect CSS selector, only to have your script break when a developer renames a . You've wrestled?

May 3

13

1

See more recommendations

Help

Status

Please rate my story

Start Discussion

0/500