Skip to content

REST API automation framework using RestAssured, TestNG, and Maven with comprehensive test reporting

Notifications You must be signed in to change notification settings

snnarangsumit/RestAssuredFramework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

REST Assured API Automation Framework

Java REST Assured TestNG Maven

🎯 Overview

Enterprise-grade REST API automation framework built with REST Assured, TestNG, and Maven. Designed for comprehensive API testing with request/response validation, JSON schema validation, and detailed reporting.

✨ Key Features

  • βœ… REST Assured - Powerful API testing library
  • βœ… TestNG Framework - Test management and parallel execution
  • βœ… Maven Build - Dependency management
  • βœ… Request/Response Validation - Comprehensive assertions
  • βœ… JSON Schema Validation - Contract testing
  • βœ… Environment Management - Multi-environment support
  • βœ… Logging - Log4j integration
  • βœ… HTML Reports - Detailed test execution reports
  • βœ… Data-Driven Testing - Parameterized test support

πŸ“‹ Prerequisites

  • Java 11 or higher
  • Maven 3.6+
  • IDE (Eclipse, IntelliJ IDEA, or VS Code)

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/snnarangsumit/RestAssuredFramework.git
cd RestAssuredFramework

# Install dependencies
mvn clean install

# Run tests
mvn test

πŸ“ Project Structure

RestAssuredFramework/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/java/
β”‚   β”‚   β”œβ”€β”€ api/               # API endpoint classes
β”‚   β”‚   β”œβ”€β”€ utils/             # Utility classes
β”‚   β”‚   └── models/            # POJO classes for request/response
β”‚   β”‚
β”‚   └── test/java/
β”‚       └── tests/             # Test classes
β”‚
β”œβ”€β”€ reports/                   # Test reports (auto-generated)
β”œβ”€β”€ test-output/               # TestNG output (auto-generated)
β”‚
β”œβ”€β”€ pom.xml                    # Maven configuration
β”œβ”€β”€ log4j.xml                  # Logging configuration
└── README.md                  # Documentation

πŸ”§ Configuration

Maven Dependencies (pom.xml)

<dependencies>
    <!-- REST Assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>5.3.0</version>
    </dependency>
    
    <!-- TestNG -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.7.0</version>
    </dependency>
    
    <!-- JSON Schema Validator -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>5.3.0</version>
    </dependency>
</dependencies>

πŸ§ͺ Running Tests

Run All Tests

mvn clean test

Run Specific Test Class

mvn test -Dtest=LoginAPITest

Run with TestNG XML

mvn test -DsuiteXmlFile=testng.xml

Generate Reports

mvn clean test
# Reports available in: reports/ and test-output/

πŸ“ Sample Test Example

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class APITest {
    
    @Test
    public void testGetUser() {
        given()
            .baseUri("https://reqres.in/api")
            .header("Content-Type", "application/json")
        .when()
            .get("/users/2")
        .then()
            .statusCode(200)
            .body("data.id", equalTo(2))
            .body("data.email", notNullValue())
            .log().all();
    }
    
    @Test
    public void testCreateUser() {
        String requestBody = "{"
            + "\"name\": \"John Doe\","
            + "\"job\": \"QA Engineer\""
            + "}";
        
        given()
            .baseUri("https://reqres.in/api")
            .header("Content-Type", "application/json")
            .body(requestBody)
        .when()
            .post("/users")
        .then()
            .statusCode(201)
            .body("name", equalTo("John Doe"))
            .body("job", equalTo("QA Engineer"))
            .body("id", notNullValue());
    }
}

πŸ” Test Coverage

API Test Types:

  • βœ… GET requests - Retrieve data
  • βœ… POST requests - Create resources
  • βœ… PUT/PATCH requests - Update resources
  • βœ… DELETE requests - Remove resources
  • βœ… Authentication testing
  • βœ… Header validation
  • βœ… Status code verification
  • βœ… Response body validation
  • βœ… JSON schema validation
  • βœ… Error handling

πŸ“Š Reporting

TestNG HTML Reports

  • Located in test-output/ folder
  • Open index.html in browser
  • Detailed test execution results
  • Pass/Fail statistics
  • Execution time

Custom Reports

  • Located in reports/ folder
  • HTML format with detailed logs
  • Request/Response data
  • Screenshots (if applicable)

🀝 Best Practices Implemented

  1. Separation of Concerns - API endpoints, tests, and utilities separated
  2. Reusable Components - Common methods in utility classes
  3. Data-Driven Testing - External data sources support
  4. Logging - Comprehensive request/response logging
  5. Assertions - Clear and meaningful validations
  6. Error Handling - Proper exception management
  7. Configuration Management - Environment-specific settings

πŸ”§ Tech Stack

  • Java - Programming language
  • REST Assured - API testing library
  • TestNG - Testing framework
  • Maven - Build automation
  • Log4j - Logging framework
  • JSON Schema Validator - Contract validation

πŸ“š Key Concepts Covered

  • REST API testing fundamentals
  • HTTP methods (GET, POST, PUT, DELETE)
  • Request/Response validation
  • JSON parsing and validation
  • Authentication mechanisms
  • Header management
  • Query parameters
  • Path parameters
  • Request body handling
  • Response extraction

πŸ› οΈ Adding New Tests

  1. Create test class in src/test/java/tests/
  2. Extend base test class (if available)
  3. Use REST Assured DSL for API calls
  4. Add assertions using TestNG or Hamcrest matchers
  5. Run with Maven: mvn test -Dtest=YourTestClass

πŸ“§ Contact

Sumit Narang

πŸ“„ License

This project is available for reference and learning purposes.


⭐ If you find this framework helpful, please give it a star!

About

REST API automation framework using RestAssured, TestNG, and Maven with comprehensive test reporting

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published