A comprehensive, production-ready REST Assured API testing framework demonstrating modern API test automation practices with Java, Maven, TestNG, and Allure reporting. Perfect for learning API testing or building your own test automation framework.
- Overview
- Features
- Prerequisites
- Quick Start
- Project Structure
- Topics Covered
- API Testing Examples
- Running Tests
- Reporting
- Best Practices
- Public APIs Used
- Contributing
- License
- Contact
This REST Assured API Testing Framework is a complete guide to API test automation, covering everything from basic GET requests to advanced authentication, file uploads, and JSON schema validation. Built with industry best practices, this framework is ideal for:
- 🎓 Learning API Testing - Comprehensive examples for beginners and advanced users
- 🏢 Interview Preparation - Common API testing scenarios and patterns
- 🛠️ Framework Development - Starter template for building production frameworks
- 📚 Reference Guide - Quick examples for REST Assured syntax and features
✅ 30+ Test Cases covering all HTTP methods and scenarios
✅ Real-World Examples using popular public APIs
✅ Production-Ready code with proper structure and organization
✅ BDD-Style Tests using Given-When-Then pattern
✅ Allure Reporting for beautiful test reports
✅ JSON Schema Validation for contract testing
✅ POJO Serialization for type-safe API testing
- Complete HTTP Method Coverage: GET, POST, PUT, PATCH, DELETE
- Authentication Examples: Basic Auth, Bearer Token, API Key
- Request Handling: Headers, Cookies, Query Parameters, Path Parameters
- Response Validation: Status codes, JSON/XML assertions, Schema validation
- Data Handling: Serialization/Deserialization with POJOs
- File Operations: Upload (multipart) and Download
- Reporting: Allure reports with detailed test execution logs
- Modular Design: Reusable models and utilities
- TestNG Integration: Test suites, groups, and parallel execution
Before running this project, ensure you have:
- ☕ Java 11 or higher - Download JDK
- 📦 Maven 3.6+ - Install Maven
- 🌐 Internet Connection - Required for API calls to public endpoints
- 💻 IDE (Optional) - IntelliJ IDEA, Eclipse, or VS Code with Java extensions
java -version
mvn -versionGet up and running in 3 simple steps:
git clone https://github.com/beingtush/rest-assured-practice.git
cd rest-assured-practicemvn clean installmvn testThat's it! Your tests should now be running. Check the allure-results/ folder for test results.
rest-assured-practice/
│
├── src/
│ ├── main/java/com/restassured/practice/
│ │ ├── models/ # POJO classes for serialization
│ │ │ ├── Post.java
│ │ │ ├── User.java
│ │ │ └── ReqResUser.java
│ │ └── utils/ # Helper utilities
│ │ └── ConfigReader.java
│ │
│ └── test/
│ ├── java/com/restassured/practice/tests/
│ │ ├── BasicGetRequestTest.java
│ │ ├── PostRequestTest.java
│ │ ├── PutPatchDeleteTest.java
│ │ ├── QueryParametersTest.java
│ │ ├── PathParametersTest.java
│ │ ├── HeadersAndCookiesTest.java
│ │ ├── AuthenticationTest.java
│ │ ├── JsonSchemaValidationTest.java
│ │ ├── SerializationDeserializationTest.java
│ │ └── FileUploadDownloadTest.java
│ │
│ └── resources/
│ ├── schemas/ # JSON schemas for validation
│ └── testdata/ # Test data files
│
├── pom.xml # Maven dependencies
├── testng.xml # TestNG suite configuration
└── README.md # Project documentation
- Simple GET requests
- Response validation
- Status code verification
- Response time assertions
- JSON/XML parsing
- Creating resources
- Request body with JSON, XML, and Form data
- Response validation
- Content-Type handling
- Full resource updates (PUT)
- Partial updates (PATCH)
- Resource deletion (DELETE)
- Idempotency testing
- Single and multiple parameters
- Parameter encoding
- Special character handling
- Dynamic URL paths
- Path variable substitution
- RESTful resource access
- Custom headers
- Cookie handling
- Content-Type negotiation
- Accept headers
- Basic Authentication
- Bearer Token (OAuth)
- API Key authentication
- Custom auth headers
- Schema validation
- Structure verification
- Contract testing
- API versioning validation
- POJO to JSON (Serialization)
- JSON to POJO (Deserialization)
- Complex object handling
- Type-safe API testing
- Multipart form data
- File upload
- File download
- Binary data handling
@Test
public void testGetAllUsers() {
given()
.baseUri("https://jsonplaceholder.typicode.com")
.when()
.get("/users")
.then()
.statusCode(200)
.body("size()", greaterThan(0));
}@Test
public void testCreateUser() {
User user = User.builder()
.name("John Doe")
.email("john@example.com")
.build();
given()
.baseUri("https://jsonplaceholder.typicode.com")
.contentType(ContentType.JSON)
.body(user)
.when()
.post("/users")
.then()
.statusCode(201)
.body("name", equalTo("John Doe"));
}@Test
public void testUserSchemaValidation() {
given()
.baseUri("https://jsonplaceholder.typicode.com")
.when()
.get("/users/1")
.then()
.statusCode(200)
.body(matchesJsonSchemaInClasspath("schemas/user-schema.json"));
}mvn testmvn test -Dtest=BasicGetRequestTestmvn test -Dtest=BasicGetRequestTest#testGetAllUsersmvn test -DsuiteXmlFile=testng.xml- IntelliJ IDEA: Right-click on test class/method → Run
- Eclipse: Right-click on test class/method → Run As → TestNG Test
- VS Code: Use Test Runner extension
This framework uses Allure for beautiful, detailed test reports.
# Install Allure (if not already installed)
# Windows: scoop install allure
# Mac: brew install allure
# Generate and open report
mvn allure:serve- 📈 Test execution dashboard
- 🔍 Detailed test steps
- 📸 Request/Response logs
- ⏱️ Execution timeline
- 🏆 Pass/Fail statistics
This framework showcases industry best practices:
- ✅ Given-When-Then Pattern - BDD-style readable tests
- ✅ Request/Response Specifications - Reusable configurations
- ✅ Log Filters - Detailed logging for debugging
- ✅ Hamcrest Matchers - Fluent assertions
- ✅ JSON Path & XML Path - Easy data extraction
- ✅ POJO Models - Type-safe serialization/deserialization
- ✅ Schema Validation - Contract testing
- ✅ TestNG Organization - Proper test structure
- ✅ DRY Principle - No code duplication
- ✅ Proper Exception Handling - Robust error management
This framework uses free, publicly available APIs:
| API | Purpose | Documentation |
|---|---|---|
| JSONPlaceholder | Fake REST API for testing | Docs |
| ReqRes | REST API with real responses | Docs |
| HTTPBin | HTTP request & response testing | Docs |
| REST Countries | Country information API | Docs |
Contributions are welcome! Here's how you can help:
- 🍴 Fork the repository
- 🌿 Create a feature branch (
git checkout -b feature/AmazingFeature) - 💾 Commit your changes (
git commit -m 'Add some AmazingFeature') - 📤 Push to the branch (
git push origin feature/AmazingFeature) - 🔃 Open a Pull Request
- Add more test scenarios
- Improve documentation
- Add CI/CD pipeline
- Add more public API examples
- Improve error handling
This project is licensed under the MIT License - see the LICENSE file for details.
Tushar Raj
- 📧 Email: beingtush@gmail.com
- 💼 GitHub: @beingtush
- 🔗 Repository: rest-assured-practice
If you found this project helpful, please give it a ⭐️! It helps others discover this resource.
- 📘 Getting Started Guide - Complete beginner's guide
- 📗 API Reference - Detailed API documentation
- 📙 Best Practices - Industry best practices
- 📕 Troubleshooting Guide - Common issues and solutions
- 📔 FAQ - Frequently asked questions
New to API Testing? Follow this learning path:
- Start with
BasicGetRequestTest.java - Progress to
PostRequestTest.java - Learn authentication in
AuthenticationTest.java - Explore serialization in
SerializationDeserializationTest.java - Master schema validation in
JsonSchemaValidationTest.java
API Testing, REST Assured, Java API Testing, Test Automation, REST API, API Test Framework, TestNG, Maven, Allure Reports, BDD Testing, HTTP Testing, JSON Validation, API Automation, Continuous Testing, QA Automation, Software Testing, REST Assured Tutorial, API Testing Examples, Java Testing Framework, REST Assured Framework
Made with ❤️ by Tushar Raj
Happy Testing! 🚀