How to Automate your API test cases using Rest Assured

Posted By : Sana Khan | 12-Jan-2021

Rest-Assured is a JAVA library or a set of JAVA APIs that can be used for testing and validating RESTful web services. The REST-based services built on the peak of HTTP Builder are passed through this. From assisting the different REST requests to validating and verifying the responses from the different APIs you have used, Rest-Assured can do it all.

As compared to dynamic languages such as Ruby and Groovy, testing and validation in REST services using Java is more difficult. In other words, we can say it REST Assured brings the simplicity of using these languages into the Java domain. Hence you can simply create a test suite using JAVA.

 

Benefits of REST Assured:


1. REST Assured reduces the need for writing the same section of code many times.
2. Rest Assured supports for Behavior-Driven Development by using these test notation, Given, When, and Then, which makes the tests readable.

3.We can customize reports for the REST-assured.

 

How to Start:

 

To get started with REST Assured, we have to  add it as a dependency to your project. If you're using Maven  add the following entry in the pom.xml 

<dependency>
<groupId>io.rest-assured</groupId>
 <artifactId>rest-assured</artifactId>
 <version>3.0.2</version>
<scope>test</scope>
</dependency>
Validate response data:
With REST Assured, you may not only verify response body contents, even also check the correctness of technical response data, such as the HTTP response status code, the response content type, and other response headers.

  • The response status code is 200.
  • The response content type  equals "application/json."
  • The value of the response header "Content-Length" equals to system generated.

 

First simple Rest Assured script:

Given(). 
 param("a", "b"). 
header("c", "d").
when().
Method().
Then(). 
statusCode(aaa).
body("a, ”b", equalTo("c"));

 

Why Choose Oodles Technologies For DevOps Solutions?

 

We are seasoned DevOps solutions and service providers with vast experience in providing full-scale DevOps solutions for varied business requirements. Our team of DevOps professionals formulates effective strategies to strengthen your enterprise IT infrastructure and enhance operational efficiency. Our 360-degree DevOps solutions and services accelerate the software development lifecycle and ensure faster delivery with continuous deployment. For project related queries, reach us out at [email protected]

Related Tags

About Author

Author Image
Sana Khan

Sana is a highly experienced QA professional with expertise in manual, API, and performance testing. With a solid foundation in testing methodologies, she has effectively executed numerous testing projects, resulting in the delivery of high-quality software. Sana has also ventured into API automation, utilizing her skills to develop automated testing frameworks and optimize the testing process. She manages a team of 5 members and enjoys exploring new technologies and testing tools. Her contributions have been instrumental in the success of multiple projects, namely Oodles Dashboard and Oodles.com.

Request for Proposal

Name is required

Comment is required

Sending message..