Setting up REST Assured with Maven
Java, Maven, the four dependencies, and a project that runs its first test.
REST Assured is a Java library for testing HTTP APIs. It doesn't run tests by itself: it sends requests and checks responses, and a test framework, here JUnit, finds the test methods and reports the results. Maven ties the two together, downloads them, and runs everything with one command. This lesson builds that project and runs a first test. The finished project, with every test from the tutorial, is a downloadif you'd rather start from it.
What you need installed
- A JDK, version 21 or later. Any OpenJDK build works, such as Eclipse Temurin or the Microsoft Build of OpenJDK. The examples were run on 21.0.12.
- Maven 3.9 or later. Download it from the Apache Maven site, unpack it, and put its
binfolder on your PATH. - An editor that understands Maven projects. IntelliJ IDEA, Eclipse and VS Code with the Java extensions all do.
Check both from a terminal:
$ java -version
openjdk version "21.0.12.1" 2026-08-18 LTS
$ mvn -v
Apache Maven 3.9.16 (2bdd9fddda4b155ebf8000e807eb73fd829a51d5)
Java version: 21.0.12.1, vendor: Microsoft, runtime: ...The project layout
Maven expects files in fixed places. Tests and the files they read go under src/test:
rest-assured/
├── pom.xml
└── src/
└── test/
├── java/
│ └── com/testingapis/examples/
│ ├── FirstTest.java
│ ├── JsonAssertionsTest.java
│ ├── ...
│ └── ApiSpecs.java
└── resources/
└── schemas/
└── product.jsonThere's no src/mainat all. This project only contains tests of an API that lives somewhere else, which is common for API test suites: they're a separate project that points at a running server.
pom.xml
The whole build is described in one file. This is the example project's, in full:
<?xml version="1.0" encoding="UTF-8"?>
<!--
REST Assured examples for the tutorial at https://testingapis.com/learn/rest-assured.
Every test runs against the free test API at https://api.testingapis.com.
Run everything: mvn test
Run the smoke tests: mvn test -Dgroups=smoke
Point at another server: mvn test -DbaseUrl=http://localhost:8080
Send an API key: set TESTINGAPIS_KEY in the environment
-->
<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>com.testingapis</groupId>
<artifactId>rest-assured-examples</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<rest-assured.version>6.0.1</rest-assured.version>
<junit.version>6.1.3</junit.version>
<jackson.version>2.22.3</jackson.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- The HTTP client and the given/when/then API -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<!-- matchesJsonSchemaInClasspath(...) -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<!-- Turns Java objects into JSON bodies and back -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<!-- The test runner, including parameterized tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<!-- Use JUnit display names, such as "product 1 is in electronics", in the XML reports CI reads -->
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
</configuration>
</plugin>
</plugins>
</build>
</project>Four dependencies, each with a job:
| Dependency | What it does |
|---|---|
io.rest-assured:rest-assured | Sends requests and checks responses: given, when, then |
io.rest-assured:json-schema-validator | Checks a response against a JSON Schema file (lesson 7) |
com.fasterxml.jackson.core:jackson-databind | Turns Java objects into JSON request bodies, and responses back into objects (lesson 4) |
org.junit.jupiter:junit-jupiter | Finds and runs the tests, including parameterized ones |
A few details are deliberate:
- Every dependency has
testscope, because nothing here ships to production. - JUnit's version comes from its bill of materials,
junit-bom, imported independencyManagement. That keeps JUnit's own modules on matching versions without repeating the number. - The Surefire plugin, which runs the tests during
mvn test, is pinned to a version. Leaving it unpinned gives you whatever default your Maven version ships, which can be too old to run JUnit tests at all. Itsconfigurationblock makes the test reports use readable names; lesson 7 shows why that matters. maven.compiler.releaseis 21, so the tests can use records and other recent Java features, as lesson 4 does.
The versions were current in October 2026 and had been out for at least a few weeks when the examples were run: REST Assured 6.0.1, JUnit 6.1.3, Jackson 2.22.3. Newer versions usually work. If one doesn't, the version that last passed is the one in the file.
The first run
Lesson 2 explains the test itself. For now, run it. The first run downloads the dependencies, so it takes a while; later runs are quick:
$ mvn test -Dtest=FirstTest
[INFO] Running com.testingapis.examples.FirstTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.737 s -- in com.testingapis.examples.FirstTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
[INFO] Total time: 13.174 s-Dtest=FirstTest runs one class; plain mvn testruns all of them. Two tests ran, against the live API, and passed. When something goes wrong at this stage, it's almost always one of three things:
| Message | Cause |
|---|---|
mvn: command not found | Maven's bin folder isn't on your PATH |
release version 21 not supported | Maven is using an older JDK; check JAVA_HOME |
Tests run: 0 | Test classes outside src/test/java, or Surefire too old to find JUnit tests |
Exercise
Download the example project, unzip it and run mvn test. Note how many tests ran and how long the build took. Then run it a second time and compare the time. Finally, break pom.xml on purpose by changing junit.version to a version that doesn't exist, such as 0.0.1, and read Maven's error.