Skip to content

snnarangsumit/RestAssuredFramework

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

 
 
 

Contributors