How freeautomationlearning/restassurredcucumber works
Project Type and Purpose
• This is an API testing framework for RESTful services. It uses Java, Cucumber (for BDD with Gherkin feature files), and RestAssured to execute API requests. It also supports mocking (via WireMock) and detailed reporting (via ExtentReports).
• The project is structured for testing rather than production application deployment. The tests are organized under the 'src/test' directory, while a minimal production support layer exists under 'src/main' (e.g., the APIFactory and reporting hook classes).
File Structure
• Top-Level Files:
• pom.xml: Indicates Maven is used for dependency and build management.
• README.md: Provides high-level instructions about setup, running tests, and configuration.
• Source Code:
• src/main/java/com/freeautomation: Contains the base classes, API factory implementation, reporting hooks, and utility classes. This layer sets up the API client and reporting modules.
• Test Code:
• src/test/java/com/freeautomation: Contains packages for constants, POJO objects (data models), step definitions (linked to the Gherkin features), and the test runner.
• src/test/resources: Contains configuration (config.json), feature files (Gherkin scenarios), report configuration files, and WireMock related files for mocking responses.
• The presence of WireMock files, feature files, and extensive report configurations indicate clear separation of concerns:
• Test Runner and Step Definitions for executing tests.
• API client module (via APIFactory) for API interactions.
• Reporting module (via Hooks and Hooks_ExtentReport) to generate detailed reports.
Key Components & Relationships
a. API Client Layer (src/main):
• Component: APIFactory and APIFactoryImplementation.
• Role: To abstract the API invocation, set up REST-like interactions, and handle dynamic requests (path parameters, query parameters, etc.).
• Interaction: Called by step definitions to perform actual HTTP operations.
b. Reporting Module (src/main):
• Components: Hooks and Hooks_ExtentReport.
• Role: Integration with ExtentReports to log and generate HTML, PDF, and even Excel format reports after tests execution.
• Interaction: Hooks are invoked during test lifecycle events.
c. Testing Framework Layer (src/test):
• Components: Feature files (Gherkin-based scenarios), Step Definitions (implementation mapping to test steps), and Runner (test execution entry point).
• Role: Executes test scenarios, which internally use the API client layer to perform calls.
• Interaction: Runner triggers tests that execute HTTP requests via the API client and log results via the reporting module.
d. Configuration & Resources:
• Components: config.json (configuration for API endpoints and WireMock), and constants in src/main/java/com/freeautomation/utils/Constants.java.
• Role: Contains environment-specific variables, API URIs, and configuration details needed by tests.
• Interaction: Both the API client and testing layers read from these configuration files.
e. Mocking Layer:
• Component: WireMock files in the resources directory.
• Role: Provide pre-defined responses for API calls to eliminate external dependencies during testing.
• Interaction: The APIFactoryImplementation uses these files (e.g., in set up for POST/GET etc.) to simulate actual API responses.