Setting Up the Environment

To start using REST Assured for API testing, you need to set up your development environment. Follow these simple steps to get everything ready:

1. Install Java Development Kit (JDK)

REST Assured is a Java-based tool, so you need to have the Java Development Kit (JDK) installed on your system.

  • Check if Java is installed: Open a terminal (Command Prompt or Shell) and type:
java -version

If Java is installed, you will see the version number.

  • Install Java (if not installed): Download and install the latest JDK from Oracle's website or use OpenJDK.

2. Set Up an IDE (Integrated Development Environment)

An IDE helps you write, organize, and run your code easily. Popular options include:

  • IntelliJ IDEA: Recommended for Java development.
  • Eclipse IDE: Another popular option for Java developers.

Download and install your preferred IDE from their official websites.

3. Create a Maven Project

Maven is a tool that helps you manage Java dependencies (external libraries) easily.

  • In IntelliJ IDEA:
    1. Go to File → New Project.
    2. Select Maven and choose the latest JDK.
    3. Enter a project name and location.
  • In Eclipse IDE:
    1. Go to File → New → Maven Project.
    2. Choose a simple Maven template and configure the project.

4. Add REST Assured Dependency

To use REST Assured, add the following dependency to the pom.xml file:

XML
Copy
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>5.5.0</version>
    <scope>test</scope>
</dependency>

After adding the dependency, reload or update the Maven project to download REST Assured.

5. Verify the Setup

Create a simple REST Assured test to ensure everything works correctly.

Java
Copy
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class SetupTest {
    public static void main(String[] args) {
        given()
            .when().get("http://192.xxx.xx.xxx:8080/books/20250401")
            .then().statusCode(200)
            .body("isbn", equalTo(20250401));
    }
}

Run this code in your IDE. If everything is set up correctly, the test should pass and validate the API response.