Method for automatically updating test case based on interface version management

By automatically loading and parsing Swagger documents to generate test cases, and monitoring document changes, automatically update test cases, solving the time-consuming and labor-consuming problem of manually writing test cases, and achieving efficient and automated test case management and execution.

CN119415432AActive Publication Date: 2025-02-11YUKUAI CHUANGLING INTELLIGENT TECH (NANJING) CO LTD

Patent Information

Application Number
CN202411520347.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-11
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

In the prior art, testers need to manually write a large number of test cases, which is time-consuming and labor-intensive, and work inefficient, especially when there are a large number of interfaces and complex parameters.

Method used

By loading the configuration file, obtaining the Swagger document and generating the V1 version of the document, parsing the Swagger document to generate test cases, and monitoring Swagger document changes to automatically update the test cases.

Benefits of technology

It realizes automated tests without manual writing of test cases, improves testing efficiency, reduces testing time, reduces labor costs, and significantly improves the efficiency of interface version management and the accuracy of testing work.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415432A_ABST
    Figure CN119415432A_ABST
Patent Text Reader

Abstract

The invention provides a method for automatically updating a test case based on interface version management. The method comprises the following steps: S1, loading a configuration file; s2, a Swager document is obtained, and a Swager document of a V1 version is generated; s3, the Swagger document is analyzed, and a test case is generated; s4, monitoring the change of the Swager document; s5, executing the interface test case; s6, generating and sending a test report; according to the method for automatically updating the test case based on interface version management provided by the invention, the test case is automatically generated by identifying the swagger document address and monitoring the change of the document, and a tester does not need to manually write the test case, so that the test efficiency is improved, and the labor cost is reduced; according to the method provided by the invention, the version change of the test case interface can be identified, and the interface version management efficiency and the test work accuracy are remarkably improved; the method is suitable for software development projects requiring frequent interface version updating.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method for automatically updating test cases based on interface version management. Background Art

[0002] R&D personnel need to write interface documents before developing a project. With the popularization of OpenAI specifications, Swagger has also entered the 3.x stage. Swagger 3.x refers to the Swagger tool version that supports the OpenAPI 3.0 specification, which places more emphasis on the support and standardization of RESTful APIs, provides richer and more flexible definition methods, and can be used to automatically generate documents, client code, server code, and testing tools. At present, most company R&D personnel use Swagger to generate interface documents. Swagger generates Swagger documents based on OpenAPI version 3.0 and above. A small number of R&D personnel use word documents to write interface documents, while testers rely on the Swagger documents provided by the developer to write test cases. Due to the large number of interfaces and complex parameters, testers need to manually write a large number of test cases, which is time-consuming and labor-intensive, and has low work efficiency. Summary of the invention

[0003] The purpose of the present invention is to solve the shortcomings in the prior art and to propose a method for automatically updating test cases based on interface version management.

[0004] To achieve the above object, the present invention adopts the following technical solutions: A method for automatically updating test cases based on interface version management, comprising the following steps: S1: Load configuration file; A user-defined configuration file, which includes the URL address of the Swagger document and basic environment information; The configuration file is a JSON file that can be customized by the user and stored in the local computer; Load the configuration file through the main entry of the Python program and extract the URL address and basic environment information of the Swagger document; The main entry of the Python program refers to the entry file of the Python program, wherein the entry file follows a specific naming rule.

[0005] S2: Get the Swagger document and generate the V1 version of the Swagger document; Initiate an http request according to the URL address of the Swagger document in the configuration file to obtain the Swagger document; The obtained Swagger document is saved locally, and a document containing the V1 version identifier is generated locally. The file name of the document is unique. The format of the file name is: version identifier+date+self-incrementing serial number.

[0006] S3: parses the Swagger document and generates test cases; Use the swagger-parser library to parse the document containing the V1 version identifier generated in step S2 into a Python object, and extract the API path and request information from the parsed Python object; The request information includes request method, request parameters, expected results, etc. Traverse the parsed API path and request information, and generate a unique ID as an identifier for each API interface; Use the requests library to build interface test cases. Each interface test case contains the API path, unique ID, request method, request parameters, and expected results. Save the constructed interface test cases into the interface test case set.

[0007] S4: monitor Swagger document changes; The following sub-steps are included: S41: Listen for Swagger document update events; Use the watchdog library to monitor Swagger document update events; Specifically, an observer class is created in the watchdog library, and the path of the Swagger document to be monitored is specified in the observer class to monitor the Swagger document; and the on_modified function is rewritten in the observer class; when the Swagger document is modified, the on_modified method is triggered, and step S42 is entered; S42: Get the latest Swagger document and generate the V2 version of the document; Use an HTTP GET request to obtain the modified Swagger document, use the datetime component of the Python program to obtain the timestamp of the modified Swagger document, and save the Swagger document as a document containing a V2 version identifier; The file name format is: version identifier + date + self-incrementing serial number; S43: Check whether the API path and request information in the Swagger documents of versions V1 and V2 have changed; The following sub-steps are included: S431: Compare whether the API path has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the API paths of the V1 and V2 versions of the Swagger document respectively; Compare the API paths of the Swagger documents of versions V1 and V2 to see if they are the same. If they are different, record the changed API paths. S432: Compare whether the request method has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request methods of the V1 and V2 versions of the Swagger document respectively; Compare the request methods of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request methods. S433: Compare request parameters to see if they have changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request parameters of the V1 and V2 versions of the Swagger document respectively; Compare the request parameters of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request parameters. S44: Update interface test cases; Update any interface test cases in the interface test case set where the API path, request method, or request parameter has changed.

[0008] S5: Execute interface test cases; Execute the interface test cases included in the interface test case set, record the execution result of each interface test case, and compare the execution result with the expected result. If they are inconsistent, the test result is a failure case; if they are consistent, the test result is a success case.

[0009] S6: Generate and send test report; Create a test report in HTML format using BeautifulSoup, where the test report contains interface test cases, execution results, and test results; Use the smtplib component to send the test report to relevant personnel by email.

[0010] Compared with the prior art, the present invention has the following beneficial effects: The present invention proposes a method for automatically updating test cases based on interface version management, which automatically generates test cases by identifying the swagger document address and monitoring the changes of the document, and does not require testers to manually write test cases, thereby improving test efficiency, reducing test time and reducing labor costs; The method provided by the present invention can identify version changes of test case interfaces, significantly improving the efficiency of interface version management and the accuracy of testing work; it is suitable for software development projects that require frequent interface version updates, especially in microservice architecture and API-driven development environments, and can significantly improve the efficiency and quality of interface management and testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 The present invention is a flowchart of the steps of a method for automatically updating test cases based on interface version management. DETAILED DESCRIPTION

[0012] In order to provide a further understanding of the purpose, structure, features, and functions of the present invention, the following detailed description is given in conjunction with the embodiments.

[0013] like Figure 1 As shown, a method for automatically updating test cases based on interface version management includes the following steps: S1: Load configuration file; A user-defined configuration file, which includes the URL address of the Swagger document and basic environment information; The configuration file is a JSON file that can be customized by the user and stored in the local computer; Load the configuration file through the main entry of the Python program and extract the URL address and basic environment information of the Swagger document; The main entry of the Python program refers to the entry file of the Python program, wherein the entry file follows a specific naming rule.

[0014] S2: Get the Swagger document and generate the V1 version of the Swagger document; Initiate an http request according to the URL address of the Swagger document in the configuration file to obtain the Swagger document; The obtained Swagger document is saved locally, and a document containing the V1 version identifier is generated locally. The file name of the document is unique. The format of the file name is: version identifier + date + self-incrementing serial number, for example V1_202409230001.

[0015] S3: parses the Swagger document and generates test cases; Use the swagger-parser library to parse the document containing the V1 version identifier generated in step S2 into a Python object, and extract the API path and request information from the parsed Python object; The request information includes request method, request parameters, expected results, etc. Traverse the parsed API path and request information, and generate a unique ID as an identifier for each API interface; Use the requests library to build interface test cases. Each interface test case contains the API path, unique ID, request method, request parameters, and expected results. Save the constructed interface test cases into the interface test case set.

[0016] S4: monitor Swagger document changes; The following sub-steps are included: S41: Listen for Swagger document update events; Use the watchdog library to monitor Swagger document update events; Specifically, an observer class is created in the watchdog library, and the path of the Swagger document to be monitored is specified in the observer class to monitor the Swagger document; and the on_modified function is rewritten in the observer class; when the Swagger document is modified, the on_modified method is triggered, and step S42 is entered; S42: Get the latest Swagger document and generate the V2 version of the document; Use an HTTP GET request to obtain the modified Swagger document, use the datetime component of the Python program to obtain the timestamp of the modified Swagger document, and save the Swagger document as a document containing a V2 version identifier; The file name format is: version identifier + date + self-incrementing serial number, for example V2_202409230001; S43: Check whether the API path and request information in the Swagger documents of versions V1 and V2 have changed; The following sub-steps are included: S431: Compare whether the API path has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the API paths of the V1 and V2 versions of the Swagger document respectively; Compare the API paths of the Swagger documents of versions V1 and V2 to see if they are the same. If they are different, record the changed API paths. S432: Compare whether the request method has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request methods of the V1 and V2 versions of the Swagger document respectively; Compare the request methods of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request methods. S433: Compare request parameters to see if they have changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request parameters of the V1 and V2 versions of the Swagger document respectively; Compare the request parameters of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request parameters. S44: Update interface test cases; Update any interface test cases in the interface test case set where the API path, request method, or request parameter has changed.

[0017] S5: Execute interface test cases; Execute the interface test cases included in the interface test case set, record the execution result of each interface test case, and compare the execution result with the expected result. If they are inconsistent, the test result is a failure case; if they are consistent, the test result is a success case.

[0018] S6: Generate and send test report; Create a test report in HTML format using BeautifulSoup, where the test report contains interface test cases, execution results, and test results; Use the smtplib component to send the test report to relevant personnel by email.

[0019] The present invention can be easily integrated into the continuous integration / continuous deployment (CI / CD) process by combining the automatic generation of test cases with the automated testing framework; it helps to discover and fix problems in the early stages of software development and improve the speed and quality of software delivery; in addition, automated testing can also perform repeated testing to ensure the stability and reliability of the software in different environments.

[0020] The present invention has been described by the above-mentioned relevant embodiments, however, the above-mentioned embodiments are only examples for implementing the present invention. It must be pointed out that the disclosed embodiments do not limit the scope of the present invention. On the contrary, changes and modifications made without departing from the spirit and scope of the present invention are all within the scope of patent protection of the present invention.

Claims

1. A method for automatically updating test cases based on interface version management, characterized in that: The following steps are involved: S1: Load configuration file; A user-defined configuration file, which includes the URL address of the Swagger document and basic environment information; The configuration file is a JSON file that can be customized by the user and stored in the local computer; Load the configuration file through the main entry of the Python program and extract the URL address and basic environment information of the Swagger document; S2: Get the Swagger document and generate the V1 version of the Swagger document; Initiate an http request according to the URL address of the Swagger document in the configuration file to obtain the Swagger document; The obtained Swagger document is saved locally, and a document containing the V1 version identifier is generated locally. The file name of the document is unique. S3: parses the Swagger document and generates test cases; Use the swagger-parser library to parse the document containing the V1 version identifier generated in step S2 into a Python object, and extract the API path and request information from the parsed Python object; The request information includes request method, request parameters, and expected results; Traverse the parsed API path and request information, and generate a unique ID as an identifier for each API interface; Use the requests library to build interface test cases. Each interface test case contains the API path, unique ID, request method, request parameters, and expected results. Save the constructed interface test cases into the interface test case set; S4: monitor Swagger document changes; The following sub-steps are included: S41: Listen for Swagger document update events; S42: Get the latest Swagger document and generate the V2 version of the document; S43: Check whether the API path and request information in the Swagger documents of versions V1 and V2 have changed; S44: Update interface test cases; Update the interface test cases in the interface test case set if any of the API paths, request methods, or request parameters have changed; S5: Execute interface test cases; Execute the interface test cases included in the interface test case set, record the execution result of each interface test case, and compare the execution result with the expected result. If they are inconsistent, the test result is a failure case; if they are consistent, the test result is a success case; S6: Generate and send a test report.

2. The method for automatically updating test cases based on interface version management according to claim 1, characterized in that: In step S41, the watchdog library is used to monitor the Swagger document update event; Specifically, an observer class is created in the watchdog library, and the path of the Swagger document to be monitored is specified in the observer class to monitor the Swagger document; and the on_modified function is rewritten in the observer class; when the Swagger document is modified, the on_modified method is triggered, and step S42 is entered.

3. The method for automatically updating test cases based on interface version management according to claim 1, characterized in that: In step S42, an HTTP GET request is used to obtain the modified Swagger document, and the datetime component of the python program is used to obtain the timestamp of the modified Swagger document, and the Swagger document is saved as a document containing a V2 version identifier.

4. The method for automatically updating test cases based on interface version management according to claim 1, characterized in that: Step S43 includes the following sub-steps: The following sub-steps are included: S431: Compare whether the API path has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the API paths of the V1 and V2 versions of the Swagger document respectively; Compare the API paths of the Swagger documents of versions V1 and V2 to see if they are the same. If they are different, record the changed API paths. S432: Compare whether the request method has changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request methods of the V1 and V2 versions of the Swagger document respectively; Compare the request methods of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request methods. S433: Compare request parameters to see if they have changed; Use the JSON library to parse the V1 and V2 versions of the Swagger document, traverse the parsed Swagger document, and extract the request parameters of the V1 and V2 versions of the Swagger document respectively; Compare the request parameters of the Swagger documents of versions V1 and V2 to see if they are the same. If there are differences, record the changed request parameters.

5. The method for automatically updating test cases based on interface version management according to claim 1, characterized in that: In step S6, a test report in HTML format is created by BeautifulSoup, wherein the test report includes interface test cases, execution results, and test results; Use the smtplib component to send the test report to relevant personnel by email.

Citation Information

Patent Citations

  • Interface document acquisition method and device and server

    CN112583891A

  • Swager annotation generation method and device, equipment and storage medium

    CN115878175A

  • Method and device for automatically generating and executing interface test case and application of method and device

    CN118689777A

  • Intelligent discovery and application of API changes for application migration

    US20190303135A1

  • Selective Invocation of RPA Workflows Via API Calls

    US20240255920A1

Cited By

  • Automatic interface testing method and related device

    CN120596394A

  • An interface automation testing method and related apparatus

    CN120596394B

  • Automatic testing method and device for micro-service architecture, electronic equipment and storage medium

    CN120631746A