Book API Testing Framework
A comprehensive framework for automated API testing of a Book system.
Tech Stack
Label | Tool |
---|---|
Language | Java 21+ |
API Testing | Rest Assured |
Test Framework | TestNG |
Reporting | Allure |
Logging | Log4j2 |
JSON | Jackson (serialization/deserialization) |
Assertions | Hamcrest |
Build Tool | Maven |
Key Functionalities
- Node.js Book API: RESTful API for books (CRUD, search, pagination, auth, rate limiting)
- Java Test Suite: TestNG + RestAssured for automated API tests (Create, Get, Update, Delete)
- Test Groups: Organized test execution with smoke, regression, and negative test groups for targeted testing strategies
- Parallel Execution: Support for parallel test execution to reduce overall test execution time and improve CI/CD pipeline efficiency
- Retry Logic (retryRequest): Retries API requests on HTTP 429, using Retry-After header or default interval
- RetryAnalyzer: TestNG retry analyzer for HTTP 429, with logging and Allure step reporting
- Logger & Custom Logging: Log4j2 and RestAssuredLogFilter for detailed HTTP and test logs
- Allure Reporting: Comprehensive test reporting with Allure framework, providing detailed insights into test execution and results
- CI/CD Ready: GitHub Actions workflow for automated test execution and reporting
- Test Results JSON Collection: Exports TestNG results to structured JSON with test outcomes, durations, and iteration details.
Key Classes & Utilities
- Book.java: POJO for book entity (id, title, author). Used as the data model for API payloads and responses.
- JsonUtils.java: Utility for JSON serialization/deserialization using Jackson. Simplifies conversion between Java objects and JSON strings for API requests and responses.
- RestAssuredLogFilter.java: Custom RestAssured filter for HTTP logging. Captures and logs HTTP requests and responses for debugging and reporting, integrates with Log4j2 and Allure.
- BaseTest.java: Abstract base for API tests. Handles test setup/teardown, authentication, retry logic, logging, and provides common utilities for all test classes.
- Test Utils (testUtils/):
- AnnotationTransformer.java: Dynamically modifies TestNG annotations at runtime, enabling features like retry logic and custom listeners without changing test code.
- RetryAnalyzer.java: Implements TestNG's retry logic for flaky tests, especially for handling HTTP 429 (rate limit) responses. Integrates with Allure for reporting retries.
- TestResultLoggerListener.java: Listens to test execution events, logs results, and integrates with Allure and Log4j2 for detailed reporting and debugging.
- Assertion.java: Provides custom assertion methods with enhanced logging using Log4j2, making test failures easier to diagnose.
- LoggingMatcher.java: Custom Hamcrest matcher that logs assertion details, improving the expressiveness and traceability of test assertions.
- TestResultsReporter.java: Collects and exports test results to JSON
- TestResultsRecords.java: Data structures for test results JSON
Project Structure
book-api-rest-assured-test-automation/
│
├── .github/ # GitHub workflows and actions
│ └── workflows/
│ └── test-execution.yml # CI workflow for running tests
├── .gitignore # Git ignore rules
│
├── github-pages/ # Static site for documentation/demo
│ ├── index.html
│ └── style.css
│
├── pom.xml # Maven build and dependencies
│
├── README.md # Project documentation
│
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ ├── pojos/
│ │ │ │ └── Book.java # Book POJO for API payloads
│ │ │ └── utils/
│ │ │ ├── JsonUtils.java # JSON utility methods
│ │ │ └── RestAssuredLogFilter.java # Custom RestAssured logging
│ │ │
│ │ └── resources/
│ │ └── log4j2.xml # Logging configuration
│ │
│ └── test/
│ └── java/
│ ├── tests/
│ │ ├── BaseTest.java # Test base class
│ │ ├── TS01_CreateBook.java # Test: Create Book
│ │ ├── TS02_GetBook.java # Test: Get Book
│ │ ├── TS03_UpdateBook.java # Test: Update Book
│ │ └── TS04_DeleteBook.java # Test: Delete Book
│ │
│ └── testUtils/
│ ├── AnnotationTransformer.java # TestNG annotation helper
│ ├── RetryAnalyzer.java # Retry logic for flaky tests
│ ├── TestResultLoggerListener.java # TestNG result logger
│ ├── Assertion.java # Custom assertions with logging
│ ├── LoggingMatcher.java # Hamcrest matcher with logging
│ ├── TestResultsReporter.java # Collects and exports test results to JSON
│ └── TestResultsRecords.java # Data structures for test results JSON
│
├── test-results/ # Test output and logs
│ ├── allure-results/ # Allure results
│ └── logs/
│ └── books-api-test.log # Test execution log
├── testng.xml # TestNG suite configuration
📊 Test Groups
🔥 Smoke Tests
Critical functionality tests including basic CRUD operations with valid data
mvn clean test -Dgroups=smoke
🔄 Regression Tests
Comprehensive test coverage including all positive and negative scenarios
mvn clean test -Dgroups=regression
❌ Negative Tests
Error handling validation including unauthorized access and invalid data
mvn clean test -Dgroups=negative
🚀 CI/CD & Automation
GitHub Actions Workflow: Sophisticated CI/CD pipeline with flexible test execution and comprehensive reporting capabilities.
- Flexible Test Selection: Run specific methods, classes, or test groups
- Environment Management: Auto-configures Java 21+ and Node.js environments
- Parallel Execution: Toggle parallel test execution for faster feedback
- API Integration: Deploys and manages Book API during test execution
- Multi-Format Reporting: Allure, JavaDoc, JSON, and Azure DevOps Test Plans integration
- GitHub Pages Deployment: Automated publishing of all reports and documentation
Azure DevOps Test Plan Integration
Below are sample screenshots showing how test results are posted and visualized in Azure DevOps Test Plans:



