Using Serenity BDD with Rest Assured is a powerful combination for building readable and maintainable API test automation in Java. Serenity adds rich HTML reports, step-level detail, and a BDD-style structure to your Rest Assured API tests.

Tech Stack

ToolPurpose
Rest AssuredJava-based API testing framework
Serenity BDDReporting and structured test framework
JUnit 5 / 4Test runner
Maven/GradleDependency management

1. Maven Dependencies (pom.xml)

Add the following:

<dependencies> <!-- Serenity --> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-core</artifactId> <version>3.6.21</version> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-junit5</artifactId> <version>3.6.21</version> </dependency> <!-- Serenity Rest Assured integration --> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-rest-assured</artifactId> <version>3.6.21</version> </dependency> <!-- JSON Assertion --> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest</artifactId> <version>2.2</version> </dependency> </dependencies>

2. Sample Test Class

import net.serenitybdd.rest.SerenityRest; import net.serenitybdd.junit5.SerenityTest; import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.*; @SerenityTest public class UserApiTest { @Test public void shouldReturnUserDetails() { SerenityRest .given() .baseUri("https://reqres.in/api") .when() .get("/users/2") .then() .statusCode(200) .body("data.id", equalTo(2)) .body("data.email", containsString("@reqres.in")); } }

3. Serenity Configuration (serenity.properties)

serenity.project.name = Serenity REST API Tests serenity.outputDirectory = target/serenity-reports

4. Run Tests

mvn clean verify

The Serenity report will be generated at:

target/serenity-reports/index.html

Serenity Report Preview

Serenity gives:

  • Step-by-step execution results

  • Screenshot placeholders (API: no screenshots, but steps are shown)

  • JSON/XML response details

  • Assertions and failures highlighted