Digital Transformation Blogs - Bigdata, IoT, M2M, Mobility, Cloud

REST API Auto TC Generator Framework

Introduction: –

Today’s world is moving toward the API-based container application to support the agile development environment. The frequency of changes in requirements is bound to happen in every sprint, based on the customer feedback in the iterative model. Test automation is the only solution to keep up with the dynamic change in the development phase. With the constant change in the API contract document, it will be tough for the project to update the test automation scripts to maintain their quality. It will lead to bugs leaking in various parts of the software, such as the frontend, backend, and security vulnerabilities, which could result in significant costs to the project.

The best solution is to implement an input-driven or data-driven framework for codeless and auto-generated test cases using a swagger file. This approach will ensure test coverage, minimal manual intervention, and early detection of the bugs. This process will streamline and enable closer integration with the CI/CD pipeline, resulting in a more effective build process.

This blog will provide a step-by-step process for defining the requirements and designing, implementing, and maintaining the test automation framework.

Scope:

The REST API Auto Test Case Generator Framework will enhance test coverage and reduce the maintainability of the test script. The framework will automatically generate the test case based on the key value pair and CRUD operation by passing the REST API YAML input or swagger files.

Test Coverage – Test coverage is the key to the SDLC cycle. Based on the base test case definitions, the framework will cover important scenarios such as the edge case, boundary condition, and negative scenarios.

Test Efficiency – Lack of automation will result in lower code efficiency due to human error. Automation will increase efficiency, save time and resources, and reduce the inconsistency in test results.

Streamlining Quality Assurance – Streamlining the quality assurance process is the key to the successful completion of a project on time with fewer bugs.

Features:

The REST API Test Automation framework aims to address challenges encountered in Rest API testing, such as,

  • Test Coverage Inconsistent
  • Manual and Human Error
  • Inadequate Validation
  • Secure Endpoint Limitations in Testing
  • Complex and Challenging Scenarios

The Test Automation Framework addresses the challenges and provides the following features:

  • Test Case Generation: Creates automation for the REST API defined in the specification based on the input YAML file.
  • Run Time Parameterization: Identifies the edge case and boundary condition.
  • CRUD Operation: Creates, Reads, Updates, and Deletes actions validated using the CRUD operation.
  • Input-Driven Testing: Automatically generates test cases and test scenarios for the REST APIs based on the input data.
  • Statement Formulation for Validation: Extracts the response code, payload and schema data type used for validation from the input parsing.
  • User Authentication and Role-Based Authorization Testing: Secures Endpoint testing using user authentication and role-based authorization
  • Error Handling Testing: Handles invalid input, missing field in the key-value pair and improper payload.
  • Continuous Development Lifecycle Integration: Easily integrates with the CI/CD pipeline in the development and test environment.
Base Test Case Categorization:

The base test case categorization for the framework provides the completed coverage of the end-to-end testing of the REST API.

  • CRUD Operation: PUT, POST, DELETE, GET, etc.
  • Success Response Validation: 200 response code and message validation.
  • Edge and Boundary: Deals with the edge case, boundary condition, and wrong input value.
  • Duplication Validation: Performs duplication validation at the operation based on the use case.
  • Response Code Verification: Verifies all types of response code 100,200,300,400,500 Series as per HTTP standard.
  • Schema and Data Type Error Analysis: Ensures response payloads match predefined data schemas.
  • Negative Test Cases: Includes scenarios like invalid input, missing fields, malformed payloads, invalid keys, and missing required fields.
Test Automation Framework Architecture Design:

The Test Automation Framework is designed in such a way that it is easy to use and maintain. It provides features such as auto test case generation and seamless integration with the CI/CD pipeline.

Below are the key component designs for the same.

  • YAML Input Parser: Exports all values and stores them in the dynamic dictionary value, such as payload, path, header, response code, etc.
  • Test Case Factory: Automatically generates a test case based on the base test case defined in the base class.
  • Wrapper Functions: Creates and maintains the wrapper function libraries to reuse for validating API responses.
  • Test Environment: Pytest is used to maintain test cases and generate a details report for the test engineer to debug and group the test case easily.
  • CI/CD Integration: Integrates with the development and test environment effortlessly used by Jenkins Jobs.

REST-API

 

Test Automation Flow: The framework follows a systematic flow to ensure efficiency.

User Input File: The user imports the file that needs to be used for the test case generation.

Test Case Generator Script: Paths, headers, requests, authorization, data schemas, and response codes are parsed from the input file and stored in the file to generate the test case for every endpoint described in the YAML file.

CI/CD Action: Test cases are triggered by Jenkins Jobs, which are integrated with development deployment scripts.

Execution Framework: Pytest is selected to execute the test case using the default request library.

Test Case Execution: All test cases can be executed using a fixture; results are analyzed separately.

Wrapper Utilities: Wrapper functions/utilities are written to handle, validate, and interchange the data based on the test case.

Reporting: Reports are saved as log files or HMTL for easy usage of debugging and analysis.

Conclusion

The REST API auto test case generator framework will help to generate the test case automatically. It will reduce the time and cost of the development cycle during project execution. It is designed to manage disturbances in the agile process and accommodate dynamic changes in user-specific requirements, including last-minute requests. The maintenance of test case scripts is minimal, allowing test engineers to meet deadlines effectively and efficiently without compromising the quality of delivery and the product being tested.

 

Post Liked   1

Archives

Categories