REST APIs: Automation

blog11

Software Testing is the most important phase of the Software Development Life Cycle (SDLC).

As applications are getting mature and in the age of open source, the integration of various applications becomes the Key to Software Development/Configuration. Hence the APIs are important.

While evolution of REST APIs and Microservices allows us to integrate software applications faster, and provide much needed modularity, testing of these APIs is a huge challenge due to a variety of combinations of input and output data.

Manual Tests for APIs are -Time Consuming, Error Prone and Cost-Ineffective. Therefore, Automating API Tests is needed for the hour and Selenium-Cucumber based Behavior Driven Framework provides an effective approach to it.

Before we explore, BDD for REST APIs Automation lets understand few basics:

1.  What is REST API?

REST stands for “Representational State Transfer”. It is a set of rules that developers follow when they create API. It determines how the API looks like.

2. Why Test REST API?

API’s are exposed to the web and/or distributed over a different network which is risky and it can affect the processes/transactions based on them. Testing these API’s is necessary, to check whether these APIs behave properly and provide a trustworthy interface to transfer information from one system/application to another.

3. Automation of REST API (BDD):

There are many ways to automate tests for REST APIs, this article focuses on BDD Approach for the same.

We know, in BDD we write scenarios using Gherkin Language using GIVEN, WHEN & THEN format. For REST APIs automation,

° In Given Statement (Mention Input Data for REST API in question)

° In When Statement (Submit API, resource, http method)

° In Then Statement (Validate the response)

For Example:

A typical REST API Gherkin Test would look like below:

° GIVEN().queryParams(“key”,”value”).header(“key”,”value”).body(“put request body”).

° WHEN().post(“put resource”).

° THEN().assertThat().statusCode(200);

REST APIs are going to stay for a long period. And as we progress, the Software Industry would be requiring more of REST APIs and hence their testing. Behavior Driven Development (BDD) provides a Fast, Easy and Futuristic approach to test these APIs with the help of Selenium scripts in a cost effective manner.

Watch This Space for more details!

Leave a Reply

Your email address will not be published. Required fields are marked *