- Project Overview
- Features
- Installation
- Configuration
- Usage
- Folder Structure
- Dependencies
- Reporting and Logs
- Contributing
- License
The rest-assured-api-testing-framework is a Java-based API testing framework designed to test REST APIs with RestAssured, TestNG, and Hamcrest. This framework supports CRUD operations on multiple API endpoints, with comprehensive logging and assertions for validation. It includes support for JSON serialization/deserialization via Jackson and data randomization with JavaFaker.
GitHub Repository: rest-assured-api-testing-framework
- GoRest API: A public API offering endpoints for user and comment management. Allows testing of CRUD operations on users and comments. URL: https://gorest.co.in/public/v2
- Campus API: A simulated API for managing locations like countries. This API is primarily used for testing authentication and resource management scenarios. URL: https://gorest.co.in/public/v2
- Zippopotam.us API: A public API providing location information based on postal codes, commonly used for validating data retrieval. URL: http://api.zippopotam.us
- ReqRes API: A testing API that supports user-related operations and is used to validate request creation and response handling. URL: https://reqres.in/api
- API Testing with RestAssured: Supports
GET
,POST
,PUT
, andDELETE
requests. - POJO Modeling: Models API responses using POJO classes for deserialization.
- Behavior-Driven Development: Uses TestNG annotations for structured and readable test scenarios.
- Data Randomization: Utilizes JavaFaker for generating random data, enhancing test variety.
- Custom Request Specifications: Leverages
RequestSpecification
andResponseSpecification
for reusable configurations. - Comprehensive Logging: Logs detailed information for requests and responses.
- Dependency Injection: Provides flexibility with dependencies, managed through Maven.
- API Key Authentication: Tests API key-secured endpoints with headers.
- CRUD Operations:
- Country Management: Creates, updates, and deletes countries in the Campus API.
- User Management: Handles user creation, retrieval, updating, and deletion in the GoRest API.
- Assertions with Hamcrest: Validates responses with assertions on fields like status codes, body content, and more.
-
Clone the Repository:
git clone https://github.com/cihat-kose/rest-assured-api-testing-framework.git
-
Import the Project in IntelliJ IDEA:
- Open IntelliJ IDEA.
- Select File > Open and choose the project folder.
- Ensure Maven auto-import is enabled to download dependencies.
-
Install Plugins (if required):
- TestNG and RestAssured support plugins in IntelliJ IDEA for enhanced IDE integration.
- TestNG.xml: Contains configurations for TestNG test execution.
- pom.xml: Manages dependencies and configurations for the framework.
To run tests, use Maven or execute directly from IntelliJ IDEA.
mvn clean test
- Right-click on
TestNG.xml
and select Run to execute all tests. - Alternatively, right-click any test class or method to run specific tests.
-
Country Test:
- Located in
campus._09_CountryTest
. - Covers country creation, duplicate check, update, and deletion.
- Located in
-
User Management in GoRest:
- Located in
goRest._07_GoRestUsersTest
. - Tests user creation, retrieval by ID, update, and deletion.
- Located in
-
Comments API Test:
- Located in
goRest._08_GoRestCommentTest
. - Manages comments by creating, retrieving, updating, and deleting comments.
- Located in
-
API Key Test:
- Located in
apiKeyTest.APIKeyTest
. - Demonstrates how to authenticate requests using API keys.
- Located in
This project commonly encounters a variety of HTTP status codes in responses. Below is a summary of some frequently used status codes and their meanings:
cihat-kose/rest-assured-api-testing-framework/
│
├── src/
│ ├── main/
│ │ └── java/
│ └── test/
│ ├── java/
│ │ ├── apiKeyTest/ # API Key authentication tests
│ │ │ └── APIKeyTest.java
│ │ ├── campus/ # Campus-related API tests
│ │ │ ├── _09_CountryTest.java
│ │ │ └── Country.java
│ │ ├── goRest/ # GoRest API tests
│ │ │ ├── _07_GoRestUsersTest.java
│ │ │ └── _08_GoRestCommentTest.java
│ │ ├── model/ # POJO models for JSON data
│ │ │ ├── Location.java
│ │ │ ├── Place.java
│ │ │ ├── ToDo.java
│ │ │ └── User.java
│ └── resources/
│ └── TestNG.xml # TestNG suite configuration
├── target/ # Build output
├── images/ # Directory for project images
│ └── HTTP_Status_Codes.png # HTTP status codes image
├── pom.xml # Maven configuration file
└── README.md # Project README
Dependencies are managed in pom.xml
. Key dependencies include:
- RestAssured: For making HTTP requests to test APIs.
- TestNG: For organizing and managing test execution.
- Hamcrest: For enhanced assertions in test validations.
- Jackson: For JSON serialization and deserialization.
- JavaFaker: For generating random test data.
- SLF4J (Simple Logging Facade for Java): For logging support.
This framework logs API requests and responses, which can be useful for debugging. Logs include:
- Request and Response Bodies: Automatically logged for all test methods.
- Status Codes and Headers: Available in logs to confirm correct responses.
Test results and logs are saved in the target
directory after test execution.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE
file for details.