Skip to main content

Reporting Tools for API Automation with RestAssured

Introduction​

Reporting is a cornerstone of API automation, providing visibility into test execution results and enabling teams to identify failures quickly. While RestAssured itself does not generate detailed reports, it integrates seamlessly with reporting tools like Allure, ExtentReports, and TestNG Reports. These tools provide rich, interactive, and customizable reports that are essential for tracking progress and communicating results to stakeholders.

In this section, we’ll explore:

  1. Why Use Reporting Tools?
  2. Popular reporting tools for API automation.
  3. How to integrate these tools with RestAssured.
  4. Practical examples and best practices for generating reports.

1. Why Use Reporting Tools?​

Benefits of Reporting Tools​

  • Visibility: Provide a clear overview of test results, including pass/fail status and failure reasons.
  • Traceability: Link test cases to requirements or user stories for better traceability.
  • Debugging: Include detailed logs, screenshots, and stack traces to aid debugging.
  • Stakeholder Communication: Generate professional reports that can be shared with non-technical stakeholders.
  • Customization: Tailor reports to include metrics like execution time, test coverage, and trends.

1. Allure Framework​

Allure is a flexible and highly customizable reporting tool that generates interactive HTML reports. It supports features like test categorization, history trends, and attachments (e.g., logs, screenshots).

  • Key Features:

    • Interactive dashboards.
    • Test categorization (e.g., smoke, regression).
    • Integration with CI/CD pipelines.
    • Attachments for logs, screenshots, and other artifacts.
  • How to Integrate with RestAssured:

  1. Add Dependencies:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.21.0</version>
</dependency>
  1. Annotate Tests with Allure:
import io.qameta.allure.Description;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;

@Epic("API Testing")
@Feature("User Management")
public class UserTests {

@Test
@Description("Verify user creation via POST /users")
public void testCreateUser() {
given()
.header("Content-Type", "application/json")
.body("{ "name": "John", "email": "john@example.com" }")
.when()
.post("/users")
.then()
.statusCode(201);
}
}
  1. Generate the Report:
mvn clean test
allure serve target/allure-results

2. ExtentReports​

ExtentReports is a popular reporting library that generates visually appealing HTML reports. It supports features like step-by-step logging, charts, and screenshots.

  • Key Features:

    • Step-by-step test logs.
    • Charts and graphs for test metrics.
    • Screenshots and attachments.
    • Customizable themes and layouts.
  • How to Integrate with RestAssured:

  1. Add Dependencies:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
  1. Create and Use an ExtentReports Instance:
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class UserTests {

private static ExtentReports extent;
private ExtentTest test;

@BeforeClass
public void setup() {
ExtentSparkReporter spark = new ExtentSparkReporter("target/extent-report.html");
extent = new ExtentReports();
extent.attachReporter(spark);
}

@Test
public void testCreateUser() {
test = extent.createTest("Create User Test", "Verify user creation via POST /users");

try {
given()
.header("Content-Type", "application/json")
.body("{ "name": "John", "email": "john@example.com" }")
.when()
.post("/users")
.then()
.statusCode(201);

test.log(Status.PASS, "User created successfully");
} catch (AssertionError e) {
test.log(Status.FAIL, "User creation failed: " + e.getMessage());
}
}

@AfterClass
public void tearDown() {
extent.flush();
}
}

3. TestNG Reports​

TestNG provides built-in reporting capabilities, generating XML and HTML reports after test execution. While less customizable than Allure or ExtentReports, it is simple to use and requires no additional setup.

  • How to Use TestNG Reports:
mvn test
  • Reports generated in test-output directory:
    • index.html: Summary report.
    • emailable-report.html: Email-friendly report.

3. Best Practices for Reporting​

  1. Include Detailed Logs:
given()
.log().all()
.when()
.post("/users")
.then()
.log().all();
  1. Attach Artifacts

  2. Categorize Tests

  3. Monitor Trends

  4. Integrate with CI/CD


Conclusion​

Reporting tools enhance the visibility and traceability of API automation tests. By integrating tools like Allure, ExtentReports, or TestNG Reports, you can generate detailed, interactive, and professional reports that meet the needs of both technical and non-technical stakeholders.