Table of contents
1.
Introduction
1.1.
Know about Rest Assured
1.2.
What is Maven
2.
Basic Requirements
3.
Setup Procedure
3.1.
Open Eclipse
3.2.
Create a Maven Project
3.3.
Adding Dependencies in Pom.xml
3.4.
Check the Libraries Added
4.
Frequently Asked Questions
4.1.
What is Rest Assured?
4.2.
Why is Maven used in projects?
4.3.
Where is REST assured used?
4.4.
What are the different dependencies required for REST Assured testing?
4.5.
How can Eclipse or another IDE be configured to use Rest-Assured?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Setup a Basic REST Assured Maven Project in Eclipse IDE

Author Sneha Mallik
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello Ninjas! We will learn to setup a basic REST Assured Maven Project in Eclipse IDE today. 

Setup a Basic REST Assured Maven Project in Eclipse IDE

But first, let us learn the basic theory to know what Rest Assured, Maven and Eclipse are. Then we will move on to the implementation of the project: To setup a basic REST Assured Maven Project in Eclipse IDE.

Know about Rest Assured

REST Assured is an open-source and Java Domain-Specific Language. It was developed and maintained by Johan Halaby. It allows us to write readable, maintainable, and robust tests in Java for RESTful APIs. The test for REST Assured runs on existing unit testing frameworks like TestNG or JUnit. It extracts a lot of boilerplate code and makes your tests powerful and easy to read and maintain.     

Know about Rest Assured

What is Maven

Apache Software Foundation developed the automation tool named Maven. It is also helpful in management. Maven is written in Java to create projects in other languages, such as C#, Scala, Ruby, etc. Using the POM(Project Object Model) and plugins; Maven enables developers to construct projects, dependencies, and documentation. Maven's development is comparable to that of ANT, although it is more complex.

Any number of projects can be built by Maven into desired outputs like a jar, war, and metadata.

Maven primarily assists in the download of dependencies, which are libraries or JAR files, for Java-based applications. Due to the possibility of various versions of individual packages, the tool aids in obtaining the appropriate JAR files for each project.

Let us move on to the basic requirements section to know what is needed to be installed before the project setup.

Basic Requirements

Learning to setup a basic project in Eclipse IDE requires the following pre-requisites:

Setup Procedure

We will look into detailed steps to setup a basic REST Assured Maven Project in Eclipse IDE.

We will start with creating our first project for Rest Assured.

In the above section, we have already seen the pre-requisites, so we can assume that we should have Java on our system and we should have our required IDE, i.e., Eclipse. Maven will already be present if we have Eclipse. 

Note:  We can run our project from Eclipse, but if we want to run outside of Eclipse, for e.g., CL(Command Line), then we will need Maven on the system as well, which needs to be downloaded separately.

Let us now start with the setup process.

Open Eclipse

First, we will open our Eclipse IDE.

Eclipse ide

After this, one window pops up like the one below:

Select workspace directory

Click on "Launch" to launch your Eclipse workspace.

Create a Maven Project

Now, after our workspace opens, we will click on the following icon, i.e., "File", to create a maven project.

Select File icon

When you click on the above icon, a new text box pops up like the following:

Select maven project

Here we will select the 'Maven Project'> 'Next', which will redirect us to a new text box pop-up like the one below. Here we will be selecting the checkbox for "Create a simple project (skip archetype selection)". Then leave the rest of the fields as it is. Click on 'Next'.

Create simple maven project

The next text box then pops up where we can give "Group Id", "Artifact Id", "Name", and "Description" for the artifact.

You can fill it up like the below image:

Fill all fields: artifact id

Click on the 'Finish' button after giving the details. Now we can see a Maven project built in our Eclipse workspace with the name given in the 'Artifact Id'.

Project explorer directory

Adding Dependencies in Pom.xml

Now we will move on to our project's 'Pom.xml' file to add on some maven dependencies.

Already present pom.xml file

Now, we will add some dependencies as required in the project inside the <dependencies></dependencies> tag.

Go to the maven central repository. Here we can search for our dependencies.

After adding our dependencies, the pom.xml in the project explorer will look like this:

‘pom.xml’ File:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>BasicRestAssuredCNProject</groupId>
  <artifactId>BasicRestAssuredCNProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>REST Assured Maven Project</name>
  <description>To setup a Basic REST Assured Maven Project in Eclipse IDE (Coding Ninjas)</description>
  
  <dependencies>
	<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
	<dependency>
     	<groupId>io.rest-assured</groupId>
     	<artifactId>rest-assured</artifactId>
     	<version>5.2.0</version>
     	<scope>test</scope>
	</dependency>
 
	<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
	<dependency>
     	<groupId>io.rest-assured</groupId>
     	<artifactId>json-schema-validator</artifactId>
     	<version>5.2.0</version>
     	<scope>test</scope>
	</dependency>
 
	<!-- https://mvnrepository.com/artifact/org.testng/testng -->
	<dependency>
     	<groupId>org.testng</groupId>
     	<artifactId>testng</artifactId>
     	<version>7.6.1</version>
     	<scope>test</scope>
	</dependency>
 
	<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
	<dependency>
     	<groupId>javax.xml.bind</groupId>
     	<artifactId>jaxb-api</artifactId>
     	<version>2.4.0-b180830.0359</version>
	</dependency>

	<!-- 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/com.fasterxml.jackson.core/jackson-databind -->
	<dependency>
     	<groupId>com.fasterxml.jackson.core</groupId>
     	<artifactId>jackson-databind</artifactId>
     	<version>2.14.0-rc2</version>
	</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>
</project>


Save the pom.xml file.

Now we can go to the left panel of 'Project Explorer' to see the dependencies downloaded by Maven.

maven dependencies in directory

Check the Libraries Added

Click on 'Maven Dependencies', and we can see the various dependencies that got downloaded after adding dependencies to the 'pom.xml' file.

All maven dependencies installed

With this, we got the required dependencies downloaded for our project. We also learned how to setup a basic Rest Assured maven project in Eclipse IDE. 

Now let's move on to the FAQs section.

Must Read Apache Server

Frequently Asked Questions

What is Rest Assured?

REST Assured is a Java DSL, or Domain-Specific Language, that allows you to write powerful, readable, and maintainable tests in Java for your RESTful APIs. It is an open-source Java-based framework.

Why is Maven used in projects?

Maven primarily assists in the download of dependencies, which are libraries or JAR files, for Java-based applications. Due to the possibility of various versions of individual packages, the tool aids in obtaining the appropriate JAR files for each project.

Where is REST assured used?

Rest Assured is used to validate REST APIs using the Java library. The Java library acts as a headless client to interact with Rest web services. It is based on the Rest Assured library and can validate the server's HTTP responses.

What are the different dependencies required for REST Assured testing?

The various dependencies required for testing REST assured are: Rest assured, Rest Assured Common, Rest Assured All, testNG, and JSON-path. 

How can Eclipse or another IDE be configured to use Rest-Assured?

Step 1: In Eclipse, create a basic Maven project.

Step 2: Get the most recent stable version of the dependency "rest-assured".

Step 3: Include the mentioned Dependency in the project's "pom.xml" file in the directory.

Step 4: Create a new class and package as per need and include the TestNG library.

Conclusion

In this article, we learned to setup a basic REST assured Maven Project in Eclipse IDE. We discussed this topic in detail, along with its practical implementation.

If you would like to learn more similar to this topic, check out our related articles on-

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, JavaScript, System Design, DBMS, Java, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations. 

Happy Learning, Ninja!🥷✨

Live masterclass