DEV Community

Milan Mandal
Milan Mandal

Posted on

Modern API Testing Framework with Java + Rest Assured + Cucumber

In modern software development, API testing is critical to ensure backend services work correctly, reliably, and securely. Automated API testing helps teams validate endpoints quickly and integrate testing into CI/CD pipelines.

To demonstrate a practical approach, I built an API Automation Framework using Java and BDD principles.

This repository provides a clean and scalable structure to automate REST APIs efficiently.

๐Ÿ”— GitHub Repository

๐Ÿ“Œ Why API Automation?

Manual API testing with tools like Postman is useful for quick checks, but it becomes difficult to maintain when the number of test cases grows. A proper automation framework provides:

โœ… Faster regression testing
โœ… Reusable test components
โœ… CI/CD integration
โœ… Detailed reporting
โœ… Scalable architecture

Automation frameworks built with Java + REST Assured + BDD are widely used in enterprise QA environments.

๐Ÿ›  Tech Stack Used

This framework uses modern automation tools commonly used by SDET engineers:

Java
REST Assured
Cucumber BDD
Maven
TestNG / JUnit
JSON Schema Validation
Git & GitHub

๐Ÿ“‚ Project Structure

`

apiAutoFramework
โ”‚
โ”œโ”€โ”€ src
โ”‚ โ”œโ”€โ”€ main
โ”‚ โ”‚ โ”œโ”€โ”€ java
โ”‚ โ”‚ โ””โ”€โ”€ resources
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ test
โ”‚ โ””โ”€โ”€ java
โ”‚ โ””โ”€โ”€ com.electrolab.api
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ base
โ”‚ โ”‚ โ”œโ”€โ”€ ScenarioContext.java
โ”‚ โ”‚ โ””โ”€โ”€ TestContext.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ config
โ”‚ โ”‚ โ”œโ”€โ”€ ConfigManager.java
โ”‚ โ”‚ โ””โ”€โ”€ Environment.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ hooks
โ”‚ โ”‚ โ””โ”€โ”€ Hooks.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ managers
โ”‚ โ”‚ โ”œโ”€โ”€ ApiManager.java
โ”‚ โ”‚ โ””โ”€โ”€ TokenManager.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ mock
โ”‚ โ”‚ โ”œโ”€โ”€ MockServer.java
โ”‚ โ”‚ โ””โ”€โ”€ UserMock.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ models
โ”‚ โ”‚ โ”œโ”€โ”€ AuthResponse.java
โ”‚ โ”‚ โ””โ”€โ”€ User.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ runners
โ”‚ โ”‚ โ””โ”€โ”€ TestRunners.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ specbuilder
โ”‚ โ”‚ โ””โ”€โ”€ SpecBuilder.java
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ stepdefinitions
โ”‚ โ”‚ โ””โ”€โ”€ UserSteps.java
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ utils
โ”‚ โ”œโ”€โ”€ ApiClient.java
โ”‚ โ”œโ”€โ”€ JsonUtils.java
โ”‚ โ”œโ”€โ”€ LoggerUtils.java
โ”‚ โ””โ”€โ”€ RetryAnalyzer.java
โ”‚
โ””โ”€โ”€ resources
โ””โ”€โ”€ features
โ””โ”€โ”€ user.feature

โš™๏ธ Framework Features

โœ” BDD testing using Cucumber
โœ” API testing using RestAssured
โœ” Reusable RequestSpecBuilder
โœ” Token-based authentication handling
โœ” Environment configuration support
โœ” Modular and maintainable architecture
โœ” Logging and retry mechanisms
โœ” JSON utilities for request/response handling

๐Ÿงช Sample BDD Scenario
Feature: User API

Scenario: Get users list
Given User calls GET users API
Then response status should be 200

๐Ÿงฑ Request Specification Builder

Reusable request configuration using SpecBuilder.

public class SpecBuilder {

public static RequestSpecification getRequest() {
    return new RequestSpecBuilder()
            .setBaseUri(ConfigManager.get("qa.url"))
            .addHeader("Content-Type", "application/json")
            .build();
}
Enter fullscreen mode Exit fullscreen mode

}

๐Ÿ” Token Manager

Handles authentication tokens dynamically and injects them into API requests.

๐Ÿ”ง Running Tests
Run using Maven

Run from IDE
Run the TestRunners.java file.

๐Ÿ“Š Future Enhancements

Parallel execution

Allure reports
CI/CD integration (Jenkins / GitHub Actions)
Dockerized test execution
API contract testing
Performance testing integration`

Top comments (0)