top of page
Search

Working on your first Rest Assured test in Eclipse and Maven

Updated: Jan 5, 2021

The Pre-requisites of working on Rest Assured are,

  1. set up java

  2. Install IDE: Eclipse

  3. Set up Maven in Eclipse

To install eclipse and set up maven refer this link.



The steps to create your first Rest Assured test is,

  1. Create a Maven project, open pom.xml and add dependencies for Rest Assured and JUnit.

  2. Create a test class and Junit method

  3. Add imports, your code and hit run to see the json response in console.

Step 1: Create a Maven project, open pom.xml and add dependencies for Rest Assured and JUnit.


ree

ree

ree
ree

Now you can see the project is created, and you pom.xml looks like below.

ree

Add the following dependencies to configure Rest Assured.


<dependencies>
   		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.hamcrest</groupId>
			<artifactId>hamcrest-all</artifactId>
			<version>1.3</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.6.2</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.jayway.restassured</groupId>
			<artifactId>rest-assured</artifactId>
			<version>2.9.0</version>
			<scope>test</scope>
		</dependency>
    
  </dependencies>

ree

Right click on the pom.xml, select run as -> maven clean and again maven install.

ree

You will see this in console.

ree

Step 2: Create a test class and Junit method.

ree

ree

Create a test method "FirstRestAssuredClass", import restassured packages and add the code.


package test;
import static com.jayway.restassured.RestAssured.given;
import org.junit.Test;
public class FirstRestAssuredClass {
	
	@Test
	public void getResponse()
	{
		given().when().get("http://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1").then().log().all();
	}

}


ree


Step 3: Add imports, your code and hit run to see the json response in console.

Run the test as Junit test, and you could see the expected response in console.


ree

You can cross check the response by launching the URL in browser.


ree

Congratulations!!! You have created your first Rest Assured test. Happy Testing!!!

 
 
 

Recent Posts

See All

Comments


bottom of page