Welcome to the RestAssured-API-Testing project! This is a sample project designed to demonstrate BDD (Behavior-Driven Development) testing framework created using Cucumber and JUnit. It tests the functionality of an API that allows representatives to create and manage quotes. The framework leverages RestAssured for HTTP requests, Gson for JSON handling, and follows best practices to ensure modularity and ease of maintenance.
- Cucumber Framework Integration: Create behavior-driven test scenarios using Gherkin syntax.
- RestAssured Setup: Seamlessly handle HTTP requests and responses.
- Java and JUnit: Utilize Java for test automation and JUnit for executing tests.
- Modular Structure: Organize your test code for ease of maintenance and scalability.
Before getting started with the Quote API Testing Framework, ensure you have the following prerequisites:
- Java Development Kit (JDK)
- Integrated Development Environment (IDE)
- Maven for dependency management
- Basic understanding of Cucumber and Gherkin syntax
- Familiarity with RESTful API concepts
To set up the project, follow these steps:
Use an IDE like IntelliJ IDEA or Eclipse to open the project.
Run the following Maven commands to install project dependencies:
mvn clean install
mvn dependency:resolve
This will download and install all required dependencies specified in the pom.xml file, preparing the project for execution.
The project is divided into several packages and files under the src/test/java
directory:
-
BaseEndpoint:
- Contains the logic to make HTTP requests to the API (GET and POST).
- Utilizes the
callEndpoint()
method to send requests andJsonHelper
to serialize and deserialize JSON.
-
QuoteEndpoint:
- Inherits from
BaseEndpoint
and is responsible for interacting with the Quote API endpoints. - Includes methods for sending API requests, such as
createQuote()
,getIsAlive()
, and response parsing usingJsonHelper
.
- Inherits from
-
Constants:
- Contains commonly used constants like URLs and HTTP status codes.
-
JsonHelper:
- Utility class for serializing objects to JSON and deserializing JSON to objects using Gson.
-
PropertyLoader:
- Singleton class for managing configuration properties (e.g., base URL).
-
RequestType:
- Enum that defines the request types: GET and POST.
-
QuoteBodyDTO:
- Data Transfer Object representing the body of a quote creation request, containing the customer and list of items.
-
QuoteBodyItemDTO:
- Represents individual quote items, with fields for
item
,quantity
,unitaryPrice
, anddiscountPercentage
.
- Represents individual quote items, with fields for
-
QuoteCreateResponseDTO:
- The main response DTO for a quote creation, containing the quote and confirmation message.
-
QuoteCreateResponseLineDTO:
- Represents individual line items in the quote, including
item
,quantity
,unitaryPrice
,discount
, andlinePrice
.
- Represents individual line items in the quote, including
-
QuoteCreateResponseConfirmationDTO:
- Contains the confirmation level and message after quote creation.
-
QuoteCreateResponseQuoteDTO:
- Holds details of the overall quote, including
totalPrice
,id
, andstatus
.
- Holds details of the overall quote, including
- Hooks:
- Manages setup and teardown actions before and after all tests (
@BeforeAll
,@AfterAll
), such as setting the base URL usingPropertyLoader
.
- Manages setup and teardown actions before and after all tests (
-
QuoteStepDefinitions:
- Contains Cucumber step definitions for testing the quote creation feature.
-
StepsDataHolder:
- A utility class for holding request and response data across different steps during test execution.
- create_quote.feature:
- Cucumber feature file for testing the "Create Quote" functionality.
- Contains scenarios for creating quotes, including both valid and invalid cases (e.g., missing customer name, invalid quantity or price, discount exceeding 100%).
The RunCucumberTest
class, located in the src/test/java
directory, is the entry point for executing Cucumber tests. It uses annotations to specify the following:
-
@RunWith(Cucumber.class): This annotation indicates that the tests should be run using Cucumber's JUnit integration.
-
@CucumberOptions: This annotation configures the test execution with several important options:
features
: Points to the path where the Cucumber feature files are located.publish
: When set totrue
, it enables the publication of the test execution report.plugin
: Specifies the format and location of the report output (e.g., an HTML report generated in thetarget
directory).
This class is critical for orchestrating the execution of Cucumber feature files and generating reports for test results.
After running the tests, you can find the test execution reports in the target
directory. The reports are generated in HTML format, providing a detailed overview of the test results.