</>

Technology

Rest Assured

Difficulty

Beginner

Interview Question

How do you set up a Rest Assured project with Maven? What are the required dependencies?

Answer

Rest Assured Project Setup with Maven

Complete pom.xml Setup

XML
<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.automateqa</groupId>
    <artifactId>api-automation</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <rest-assured.version>5.3.2</rest-assured.version>
        <testng.version>7.8.0</testng.version>
    </properties>

    <dependencies>
        <!-- REST Assured Core -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>${rest-assured.version}</version>
        </dependency>

        <!-- JSON Path -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>${rest-assured.version}</version>
        </dependency>

        <!-- JSON Schema Validator -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>${rest-assured.version}</version>
        </dependency>

        <!-- TestNG -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
        </dependency>

        <!-- Jackson (for serialization/deserialization) -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.15.2</version>
        </dependency>

        <!-- Apache Commons IO (for reading files) -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.13.0</version>
        </dependency>

        <!-- Lombok (optional - reduces boilerplate in POJOs) -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.28</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Project Folder Structure

CODE
api-automation/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ main/java/
│   │   └── com/automateqa/
│   │       ā”œā”€ā”€ config/ConfigManager.java
│   │       ā”œā”€ā”€ models/User.java
│   │       └── utils/TokenManager.java
│   └── test/java/
│       └── com/automateqa/
│           ā”œā”€ā”€ base/BaseTest.java
│           └── tests/UserApiTest.java
ā”œā”€ā”€ src/test/resources/
│   ā”œā”€ā”€ config.properties
│   └── schemas/user-schema.json
ā”œā”€ā”€ pom.xml
└── testng.xml

BaseTest Setup

Java
import io.restassured.RestAssured;
import org.testng.annotations.BeforeClass;

public class BaseTest {

    @BeforeClass
    public void setup() {
        RestAssured.baseURI  = "https://reqres.in";
        RestAssured.basePath = "/api";
        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    }
}

Follow AutomateQA

Related Topics