Maven Dependencies for REST Assured
REST Assured is a Java library, so it is commonly added to a Maven project using the pom.xml file.
To build a complete API automation framework, REST Assured is typically used along with additional dependencies for JSON/XML processing, testing, reporting, and logging.
Interview Answer
"To use REST Assured in a Maven project, I add the REST Assured dependency in the
pom.xml. Depending on the project requirements, I also includejson-path,xml-path, Groovy, and TestNG or JUnit dependencies. Maven automatically downloads these libraries, making the project easy to set up and maintain."
Core REST Assured Dependency
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
JSON Path Dependency
Used for reading and validating JSON responses. Already included: rest-assured brings json-path in automatically (a transitive dependency), so you only add it separately when using JsonPath without REST Assured.
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
XML Path Dependency
Used for validating XML responses. Like json-path, it comes with rest-assured automatically — no separate entry needed in a normal REST Assured project.
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
JSON Schema Validator Dependency
Used to validate API responses against JSON Schema.
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
TestNG Dependency
If your framework uses TestNG:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.11.0</version>
<scope>test</scope>
</dependency>
JUnit Dependency
If your framework uses JUnit:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
Groovy — Don't Add It Yourself
REST Assured is built on Groovy (its GPath syntax powers body("orders.item", …)), but rest-assured already pulls in the Groovy version it was built and tested with. Adding a different Groovy version explicitly — for example Groovy 5 alongside REST Assured 5.5, which uses Groovy 4 — can cause NoSuchMethodError or ClassNotFoundException at runtime. Leave Groovy out of your pom.xml, and if you ever see Groovy errors, run mvn dependency:tree to check that only one Groovy version is present. See ClassNotFoundException vs NoClassDefFoundError.
Common Additional Dependencies
Most REST Assured frameworks also include:
- Maven Surefire Plugin
- Log4j
- Jackson Databind
- Extent Reports
- Allure Reports
- Apache POI (Excel)
- Lombok (Optional)
Maven Dependency Flow
pom.xml
│
▼
Maven Downloads Dependencies
│
▼
REST Assured
JSON Path
XML Path
TestNG / JUnit
Groovy
│
▼
Ready for API Automation
Why Use Maven?
Maven provides:
- Automatic dependency management
- Version management
- Easy project setup
- Build automation
- Test execution
- CI/CD integration
Prerequisites for REST Assured
REST Assured requires only a basic Java development environment.
Software Requirements
You should have:
- Java Development Kit (JDK)
- Java IDE (IntelliJ IDEA or Eclipse)
- Maven
- REST Assured dependencies
- TestNG or JUnit
Knowledge Prerequisites
Basic understanding of:
- Java
- REST APIs
- HTTP Methods
- JSON
- Maven
REST Assured Setup
JDK
│
▼
Java IDE
│
▼
Maven Project
│
▼
Add REST Assured Dependencies
│
▼
Write API Test Cases
Does REST Assured Require a Server?
No.
REST Assured is a lightweight Java library.
It does not require:
- Web Server
- Application Server
- API Server Installation
You only need:
- JDK
- Maven
- Java IDE
- API Endpoint
Advantages
- Easy setup
- Lightweight
- Open source
- Java-based
- No server installation required
The given(), when(), then() Syntax
REST Assured follows the BDD (Behavior Driven Development) approach.
It organizes every API test into three logical sections.
given()
│
▼
when()
│
▼
then()
Interview Answer
"
given(),when(), andthen()are the three core methods in REST Assured's BDD syntax.given()defines the request details such as headers, parameters, authentication, and request body.when()sends the HTTP request.then()validates the response, including the status code, response body, and headers."
given()
The given() section prepares the request.
It specifies:
- Base URI
- Headers
- Authentication
- Query Parameters
- Path Parameters
- Cookies
- Payload
Example
given()
.header("Authorization", "Bearer " + token)
.contentType(ContentType.JSON)
.body(payload);
when()
The when() section sends the actual HTTP request.
Supported methods include:
- GET
- POST
- PUT
- PATCH
- DELETE
Example
.when()
.post("/users");
then()
The then() section validates the response.
Common validations include:
- Status Code
- Response Body
- Headers
- Cookies
- Response Time
Example
.then()
.statusCode(201);
Complete Example
given()
.contentType(ContentType.JSON)
.body(payload)
.when()
.post("/users")
.then()
.statusCode(201)
.body("name", equalTo("John"));
Pizza Ordering Analogy
Think of ordering a pizza.
given()
You provide:
- Delivery address
- Pizza type
- Payment method
↓
when()
You place the order.
↓
then()
You verify:
- Correct pizza
- Correct size
- Delivered successfully
The same idea applies to REST Assured.
BDD Flow
given()
│
├── Headers
├── Authentication
├── Parameters
├── Payload
│
▼
when()
│
├── GET
├── POST
├── PUT
├── DELETE
│
▼
then()
│
├── Status Code
├── Response Body
├── Headers
├── Cookies
└── Response Time
Advantages of BDD Syntax
- Easy to read
- Easy to understand
- Clean structure
- Better maintenance
- Natural English-like syntax
Configuring REST Assured with TestNG
REST Assured integrates seamlessly with TestNG for test execution and reporting.
Step 1: Create a Maven Project
Create a Maven project using:
- IntelliJ IDEA
- Eclipse
- VS Code (with Maven support)
Step 2: Add Dependencies
Include:
- JSON Path
- XML Path (if required)
- JSON Schema Validator (if required)
inside the pom.xml.
Step 3: Create Test Class
public class UserTest {
@Test
public void verifyUser(){
}
}
Step 4: Write REST Assured Test
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class UserTest {
@BeforeClass
public void setUp() {
RestAssured.baseURI = "https://jsonplaceholder.typicode.com"; // free practice API, no key needed
}
@Test
public void getUser() {
given()
.accept("application/json")
.when()
.get("/users/2")
.then()
.statusCode(200)
.body("id", equalTo(2))
.body("name", equalTo("Ervin Howell"));
}
}
Three things beginners miss: the static imports (without them given() "cannot be found"), a base URI (without it REST Assured calls localhost:8080), and at least one assertion on the body — a status code alone doesn't prove the API returned the right data. The example uses JSONPlaceholder, a free practice API that needs no key.
Step 5: Create testng.xml
<suite name="REST Suite">
<test name="API Tests">
<classes>
<class name="tests.UserTest"/>
</classes>
</test>
</suite>
Step 6: Execute Tests
Execution options:
- IDE
- Maven
mvn test
TestNG Execution Flow
Maven Project
│
▼
REST Assured Test
│
▼
@Test Method
│
▼
testng.xml
│
▼
Execute Tests
│
▼
Generate Reports
Advantages of TestNG
- Test grouping
- Parallel execution
- Data Providers
- Retry Analyzer
- Test reports
- Flexible suite execution
Interview Answer
"I configure REST Assured with TestNG by creating a Maven project, adding the REST Assured and TestNG dependencies in the
pom.xml, writing API test cases inside methods annotated with@Test, and managing execution through thetestng.xmlsuite file."
Configuring REST Assured with JUnit
The setup is almost identical to TestNG.
The main difference is that JUnit uses its own annotations and assertions.
Step 1: Add Dependencies
Include:
- JUnit
inside the pom.xml.
Step 2: Create Test Class
public class UserTest {
@Test
void verifyUser(){
}
}
Step 3: Write REST Assured Test
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
class UserTest {
@BeforeAll
static void setUp() { // static in JUnit 5
RestAssured.baseURI = "https://jsonplaceholder.typicode.com";
}
@Test
void getUser() {
given().when().get("/users/2")
.then().statusCode(200).body("name", equalTo("Ervin Howell"));
}
}
Step 4: Execute Tests
Run using:
- IDE
- Maven
mvn test
- Jenkins
TestNG vs JUnit
| Feature | TestNG | JUnit |
|---|---|---|
| Annotation | @Test |
@Test |
| Suite File | testng.xml |
Not Required |
| Data Provider | Yes | Parameterized Tests |
| Retry Support | Yes | Requires Extension |
| Parallel Execution | Built-in | Supported (JUnit 5) |
| Popular for Automation | Yes | Yes |
Best Practices
- Use Maven for dependency management.
- Keep all dependencies in the
pom.xml. - Use the latest stable library versions.
- Prefer TestNG for large automation frameworks.
- Use the
given(),when(),then()structure consistently. - Organize dependencies and plugins clearly in the
pom.xml.
📚 Official documentation: TestNG documentation · REST Assured official site
Frequently Asked Questions (FAQs)
1. What is the Maven dependency for REST Assured?
Add the REST Assured dependency in the pom.xml. Depending on the project, include json-schema-validator if you validate schemas, and either TestNG or JUnit for test execution.
2. What are the prerequisites for REST Assured?
REST Assured requires:
- Java Development Kit (JDK)
- Java IDE (IntelliJ IDEA or Eclipse)
- Maven project
- REST Assured dependencies
- TestNG or JUnit
- Basic knowledge of REST APIs and JSON
No server installation is required.
3. What is the purpose of given(), when(), and then()?
REST Assured follows the BDD style:
given()→ Configures the request (headers, parameters, authentication, payload).when()→ Sends the HTTP request.then()→ Validates the response (status code, body, headers, response time, etc.).
4. How do you configure REST Assured with TestNG?
Create a Maven project, add the REST Assured and TestNG dependencies in the pom.xml, write API tests using REST Assured inside methods annotated with @Test, and manage execution using the testng.xml suite file.
5. How do you configure REST Assured with JUnit?
Create a Maven project, add the REST Assured and JUnit dependencies, write API test methods using JUnit's @Test annotation, and validate responses using REST Assured assertions. Tests can be executed from the IDE, Maven, or Jenkins.
6. Does REST Assured require a server setup?
No. REST Assured is a lightweight Java library and does not require a dedicated server. You only need a JDK, a Java IDE, a Maven project with the required dependencies, and access to the API endpoints you want to test.
Watch how given(), when() and then() turn into a real HTTP request and response in the REST Assured Visualizer.
From Real Projects
I've tested APIs at the level of CRUD operations, HTTP methods and JSON path validation, and written automation in Java with TestNG. REST Assured brings those together in one Java library — which is why testers with Selenium and TestNG experience usually pick it up quickly. Start with one resource and automate its full CRUD cycle. Testsigma supports web, mobile and API test automation, so understanding APIs was part of understanding the product I was testing. Put the base URI and common headers in one shared specification.