In the previous tutorial, I have provided the Introduction of Rest Assured. In this tutorial, I will explain how to setup basic Rest Assured Maven project in Eclipse IDE. Before starting, let us recap about Rest Assured.
What is Rest Assured?
REST Assured is a Java DSL for simplifying testing of REST based services built on top of HTTP Builder. It supports POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD requests and can be used to validate and verify the response of these requests.
Rest-Assured library also provides the ability to validate the HTTP Responses received from the server. This makes Rest-Assured a very flexible library that can be used for testing.REST Assured can be used to test XML as well as JSON based web services. REST Assured can be integrated with JUnit and TestNG frameworks for writing test cases for our application.
What is Maven?
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.
Steps to setup Rest Assured Maven Project in Eclipse
- Download and Install Java on the system
- Download and setup Eclipse IDE on the system
- Setup Maven on System
- Create a new Maven Project
- Add Rest-Assured dependencies to the project
Step 1- Download and Install Java
Rest-Assured needs Java to be installed on the system to run the tests. Click here to know How to install Java.
Step 2 – Download and setup Eclipse IDE on system
The Eclipse IDE (integrated development environment) provides strong support for Java developers. Click here to know How to install Eclipse.
Step 3 – Setup Maven
To build a test framework, we need to add several dependencies to the project. Click here to know How to install Maven.
Step 4 – Create a new Maven Project
File -> New Project-> Maven-> Maven project ->Next
Step 4.1 – Select “Create a simple project”. Click on the Next Button.
Step 4.2 – Provide Group Id and Artifact Id and click on the finish button.
Group Id – com.example
Artifact Id – restassured_demo
Step 4.3 – Below is the structure of Maven project in Eclipse.
Step 4.4 – This is the structure of POM.xml created for the project.
Step 5 – Add Rest-Assured, Json Schema Validator and JUnit dependencies to the project .
<dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured --> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.3.3</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.github.fge/json-schema-validator --> <dependency> <groupId>com.github.fge</groupId> <artifactId>json-schema-validator</artifactId> <version>2.2.6</version> </dependency> </dependencies>
Step 6 – Below are the Rest Assured , json schema validator, junit jar files present under Maven Dependencies.
Points to Remember
- Don’t add dependency of JSONPath and XMLPath explicitly. RestAssured includes both by default. You can see it in the Maven Dependencies folder under your project.
2. Don’t add dependency of Hamcrest explicitly. RestAssured includes it by default. You can see in the Maven Dependencies folder under the project.