top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Building API tests with REST Assured: A Quick Step by Step Start Guide - Part 1

Rest Assured is a Java-based library used to test and validate RESTful Web Services/API (you can find differences between Web Services and API in my another blog, https://www.numpyninja.com/post/difference-between-apis-and-web-services ). It is used to invoke REST web services and check response.

It works with a variety of testing frameworks, including JUnit, TestNG, and Cucumber. It can also work with other Java-based tools like Maven and Gradle.

The architecture follows the CRUD operations, Create, Read, Update and Delete.

It also supports authentication methods, including API Keys, OAuth 2.0, HTTP Authentication Schemes, and JWT Authentication.


Advantages:

  • Rest services helps us to find defects before UI is developed

  • The clients and servers can interact in complex ways without the client knowing anything beforehand about the server and the resources it hosts

  • Rest API's are stateless and cache-less. They don't store information.

  • REST is implemented in XML as well as JSON

  • REST Assured supports the BDD syntax, Given/When/Then

  • REST Assured provides a domain-specific language (DSL) for writing powerful, maintainable tests for RESTful APIs


Disadvantages:

  • No built in reporting functionality

  • REST Assured does not explicitly support SOAP APIs testing

  • Requires good programming knowledge in JAVA


In this blog, we’ll see how to set up REST Assured project


Prerequisites: Need Java and Maven in the system, an IDE like Eclipse or IntelliJ and testNG framework, hoping all these are already installed in your system, I am going to our first step.


1. Create a Maven Project

1. a) I have chosen Eclipse as my IDE, once you opened the Eclipse, go to File , New and click on Other






1. b) Then, it will display a window saying Select a wizard. Then expand on Maven, choose Maven Project and click on Next




1. c) Click on the checkbox, Create a maven Project and also choose the default workspace location





1. d) Now give the Group Id and Artifact Id, here I have given RestAssuredDemoProject and clicked on Finish. We can see our project is created under Package Explorer



2. Adding dependencies : Rest Assured dependency and testNG dependency

2. a) Open pom.xml file and add dependencies tag inside the project tag







2. b) Now, go to central maven repository, use this link https://mvnrepository.com/ and search rest assured, click on the latest version and copy and paste the dependency in pom.xml inside dependencies tag. Repeat the same step with testNG to add testNG dependency








<dependencies>

<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured --> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>5.3.2</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.8.0</version> <scope>test</scope> </dependency>

</dependencies>


2. c) Now click on Save. We will be able to see Maven Dependancies folder got added under our project and also testNG added inside it




3. Install testNG plugins


3. a) This is our final step, let’s go to the Help in navigation bar and click on Eclipse Marketplace



3. b) Search for testNG plugin, in my system it’s already installed, if its not installed in your system, please click on install and accept the license agreement and click on Finish. The Eclipse will prompt to restart, click on Restart




So, here we go, we have done the initial set up for our project. Let’s see how to create and run the tests in REST Assured in part 2 (https://www.numpyninja.com/post/building-api-tests-with-rest-assured-a-quick-step-by-step-start-guide-part-2 ).


Thank you for reading.


145 views0 comments

Recent Posts

See All
bottom of page