Interface testing method and device, equipment and storage medium

By automatically synchronizing and generating test cases, the problem of manual operation dependence in the existing technology is solved, and efficient and accurate automatic generation of interface test results is achieved.

CN120336173APending Publication Date: 2025-07-18SHENZHEN QIANHAI EVOC ASIA-PACIFIC ELECTRONIC EQUIP TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510404099.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-01
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, the writing and management of automated test cases relies on manual operations, resulting in inefficient testing and error-prone, and the inability to automatically generate test results, and the generated test cases cannot be synchronized, resulting in waste of resources and insufficient feedback on test results.

Method used

By obtaining the document to be parsed, it is determined whether it is the first parsing. If not, the test cases corresponding to the document to be parsed are synchronized, a second test case is generated, and the target interface is tested based on these use cases to generate interface test results.

Benefits of technology

Reduces human errors, keeps test cases synchronized with documents, reduces the risk of missing test case updates due to document updates, and improves the efficiency and accuracy of automatic generation of interface test results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120336173A_ABST
    Figure CN120336173A_ABST
Patent Text Reader

Abstract

The invention discloses an interface testing method and device, equipment and a storage medium, and relates to the technical field of software test.The interface testing method comprises the steps that a to-be-analyzed document is obtained, and whether the to-be-analyzed document is analyzed for the first time or not is judged; if not, synchronizing a plurality of first test cases corresponding to the to-be-analyzed document to obtain a plurality of second test cases; and based on each second test case, testing a target interface to generate an interface test result. According to the method and the device, human errors occurring in interface testing can be reduced, and the test case and the document are kept synchronous, so that the risk that updating of the test case is omitted due to document updating is reduced, and then the efficiency and the accuracy of automatic generation of the interface testing result are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of software testing, and in particular to an interface testing method, apparatus, device and storage medium. Background Art

[0002] In the field of software development, the documentation and testing of APIs (Application Programming Interfaces) are key links to ensure software quality. As a widely used API description language, Swagger (now known as OpenAPI) can automatically generate API documentation and provide a human-computer interactive testing interface, improving the development and testing efficiency of APIs.

[0003] However, although Swagger provides the function of automatically generating API documentation, the writing and management of automated test cases often rely on manual operations, which not only leads to low testing efficiency and is prone to errors, but also cannot synchronize the documents for which test cases have been generated, but instead generates new test cases, resulting in waste of resources and deficiencies in test result feedback, and cannot automatically generate test results. Summary of the Invention

[0004] The main purpose of this application is to provide an interface testing method, apparatus, device and storage medium, aiming to solve the problem that the writing and management of automated test cases often rely on manual operations.

[0005] To achieve the above purpose, this application proposes an interface testing method, and the method includes:

[0006] Obtain a document to be parsed, and determine whether the document to be parsed is parsed for the first time;

[0007] If not, synchronize a number of first test cases corresponding to the document to be parsed to obtain a number of second test cases;

[0008] Based on each of the second test cases, test a target interface to generate an interface test result.

[0009] In one embodiment, the step of if not, synchronize a number of first test cases corresponding to the document to be parsed to obtain a number of second test cases includes:

[0010] If the document to be parsed is not parsed for the first time, parse the document to be parsed to obtain first interface test information, and obtain second interface test information corresponding to the document to be parsed in a preset database;

[0011] Compare the first interface test information with the second interface test information;

[0012] If there is a contrast inconsistency, then based on the first interface test information and the second interface test information, synchronize each of the first test cases to obtain a plurality of the second test cases.

[0013] In one embodiment, the synchronizing each of the first test cases based on the first interface test information and the second interface test information to obtain a plurality of the second test cases includes:

[0014] Based on the first interface test information and the second interface test information, determine a plurality of interfaces to be synchronized and the synchronization type and synchronization content corresponding to each of the interfaces to be synchronized;

[0015] Search for the first test cases corresponding to each of the interfaces to be synchronized;

[0016] Based on the synchronization type and the synchronization content, synchronize the first test cases corresponding to each of the interfaces to be synchronized to obtain a plurality of the second test cases.

[0017] In one embodiment, the determining whether the document to be parsed is a first-time parse includes:

[0018] Obtain a detection script;

[0019] Based on the detection script, detect whether there is a relevant file corresponding to the second interface test information in a preset database;

[0020] If not, determine that the document to be parsed is a first-time parse.

[0021] In one embodiment, after obtaining the document to be parsed and determining whether the document to be parsed is a first-time parse, further include:

[0022] If the document to be parsed is a first-time parse, perform document parsing on the document to be parsed to obtain second interface test information, and store the second interface test information in a preset database;

[0023] Determine a plurality of interface information in the second interface test information;

[0024] Based on each of the interface information and a preset test case template, generate a plurality of the first test cases.

[0025] In one embodiment, before generating an interface test result by testing a target interface based on each of the second test cases, further include:

[0026] Obtain user requirements, and based on the user requirements, construct a test trigger;

[0027] Detect whether to test the target interface through the test trigger;

[0028] If so, based on each of the second test cases, test the target interface to generate the interface test result.

[0029] In one embodiment, the testing the target interface based on each of the second test cases to generate the interface test result includes:

[0030] Determine the second test case corresponding to the target interface in each of the second test cases;

[0031] Based on the second test case corresponding to the target interface, test the target interface to obtain interface test data;

[0032] Parse the interface test data to generate the interface test result.

[0033] In addition, to achieve the above object, the present application also proposes an interface testing device, where the interface testing device includes:

[0034] An acquisition module, configured to acquire a document to be parsed and determine whether the document to be parsed is parsed for the first time;

[0035] A synchronization module, configured to, if the document to be parsed is not parsed for the first time, synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases;

[0036] A generation module, configured to test a target interface based on each of the second test cases to generate an interface test result.

[0037] In addition, to achieve the above object, the present application also proposes an interface testing device, where the device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the interface testing method as described above.

[0038] In addition, to achieve the above object, the present application also proposes a storage medium, where the storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium, and when the computer program is executed by a processor, the steps of the interface testing method as described above are implemented.

[0039] In addition, to achieve the above object, the present application also provides a computer program product, where the computer program product includes a computer program, and when the computer program is executed by a processor, the steps of the interface testing method as described above are implemented.

[0040] The present application provides an interface testing method, apparatus, device and storage medium. The interface testing method obtains a document to be parsed, determines whether the document to be parsed is parsed for the first time. If not, a plurality of first test cases corresponding to the document to be parsed are synchronized to obtain a plurality of second test cases. Then, based on each of the second test cases, a target interface is tested to generate an interface test result, thereby reducing human errors in interface testing and keeping the test cases synchronized with the document, thus reducing the risk of missing test case updates due to document updates, and further improving the efficiency and accuracy of automatic generation of interface test results. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application and used together with the specification to explain the principles of the present application.

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.

[0043] Figure 1 It is a schematic flowchart provided for Embodiment 1 of the interface testing method of the present application;

[0044] Figure 2 It is a schematic flowchart provided for document parsing of the interface testing method of the present application;

[0045] Figure 3 It is a schematic flowchart provided for interface testing information comparison of the interface testing method of the present application;

[0046] Figure 4 It is a schematic flowchart provided for test case generation of the interface testing method of the present application;

[0047] Figure 5 It is a schematic flowchart provided for trigger triggering of the interface testing method of the present application;

[0048] Figure 6 It is a schematic flowchart example provided for the interface testing method of the present application;

[0049] Figure 7 It is a schematic module structure diagram of the interface testing apparatus according to the embodiment of the present application;

[0050] Figure 8 It is a schematic device structure diagram of the hardware operating environment involved in the interface testing method according to the embodiment of the present application.

[0051] The implementation, functional features, and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. Specific Embodiments

[0052] It should be understood that the specific embodiments described herein are only used to explain the technical solution of the present application and are not used to limit the present application.

[0053] In order to better understand the technical solution of the present application, the following will be described in detail with reference to the accompanying drawings of the specification and specific embodiments.

[0054] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a big data service platform, an interface testing system, etc. that can implement the above functions. Hereinafter, taking the interface testing system as an example, this embodiment and the following embodiments will be described.

[0055] Based on this, the embodiment of the present application provides an interface testing method, referring to Figure 1 , Figure 1 which is a schematic flowchart provided for the first embodiment of the interface testing method of the present application.

[0056] In this embodiment, the interface testing method includes steps S11 to S13:

[0057] Step S11, obtain the document to be parsed and determine whether the document to be parsed is parsed for the first time;

[0058] It should be noted that the document to be parsed refers to a document about API (Application Programming Interface) test information, which is used to help developers design, build, document, and test APIs faster and more simply, such as a Swagger document (or an OpenAPI specification document). Among them, Swagger is an open-source API design and documentation tool that details information such as the interfaces, paths, parameters, and response formats of APIs.

[0059] Specifically, obtain the document to be parsed. In one embodiment, obtain the Swagger file through a network interface. The Swagger file can be in JSON (JavaScript Object Notation, a lightweight data interchange format that is easy for humans to read and write, and also easy for machines to parse and generate) format or YAML (YAML Ain't Markup Language, a human-readable data serialization standard for configuration files that supports complex data structures, is convenient for humans to write and read, and is also easy to parse). The Swagger file contains detailed information about all endpoints scanned by springdoc-openapi, such as paths, parameters, response types, etc., which are not restricted here.

[0060] Further, obtain the detection script, and then based on the detection script, detect whether there are relevant files corresponding to the second interface test information in the preset database. Thus, if not, it is determined that the document to be parsed is being parsed for the first time.

[0061] Step S12, if not, synchronize a number of first test cases corresponding to the document to be parsed to obtain a number of second test cases;

[0062] It should be noted that the first test case refers to the test case of the most recent version before synchronization generated according to the document to be parsed. When the document to be parsed is updated, the first test case needs to be synchronized and updated to reflect these changes. The second test case is the new version of the test case after synchronization and update, which contains the latest API change information and other API information that does not need to be synchronized.

[0063] Specifically, if the document to be parsed is not being parsed for the first time, perform document parsing on the document to be parsed to obtain the first interface test information, and obtain the second interface test information corresponding to the document to be parsed in the preset database. Then, compare the first interface test information with the second interface test information. Thus, if the comparison is inconsistent, synchronize each of the first test cases based on the first interface test information and the second interface test information to obtain a number of the second test cases.

[0064] Step S13, based on each of the second test cases, test the target interface to generate an interface test result.

[0065] It should be noted that the target interface refers to the API interface to be tested in an actual software system. The interface test result refers to the result obtained after testing the target interface, including but not limited to: interface test effect: whether each test case passes and whether the expected result is achieved; status code: the HTTP status code of the API response, used to verify whether the API returns as expected; response time: the time when the API responds, used to evaluate performance; response content: whether the data returned by the API meets the expectation, including data in formats such as JSON and XML; error information: the error information or exception details when the test fails; coverage rate: the code scope covered by the test cases; performance metrics: such as throughput and concurrent processing ability; log record: the detailed log during the test execution, used for problem diagnosis, etc., which is not limited here.

[0066] Specifically, in each of the second test cases, determine the second test case corresponding to the target interface, and then based on the second test case corresponding to the target interface, test the target interface to obtain interface test data, and thus parse the interface test data to generate the interface test result.

[0067] In this embodiment, by obtaining the document to be parsed and determining whether the document to be parsed is parsed for the first time, and then if not, synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases, and thus based on each of the second test cases, test the target interface to generate an interface test result, thereby reducing human errors in interface testing and keeping the test cases synchronized with the document, thereby reducing the risk of missing the update of test cases due to document update, and further improving the efficiency and accuracy of automatic generation of interface test results.

[0068] In a feasible implementation manner, the "if not, synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases" includes:

[0069] Step S21, if the document to be parsed is not parsed for the first time, perform document parsing on the document to be parsed to obtain first interface test information, and obtain second interface test information corresponding to the document to be parsed in a preset database;

[0070] It should be noted that the first interface test information refers to the interface test information obtained from the latest parsing that needs to be compared with the second interface test information of the most recent version before synchronization, on the premise that the document to be parsed has been parsed for the first time. It includes the updated interface definition (if there are changes in the interface path or method, these changes will be reflected in the second interface test information); the updated request parameters, including any newly added, modified, or deleted parameters; the updated response format, changes in the interface response data structure, including newly added fields, deleted fields, or changes in field types; the updated expected status code (if there are changes in the expected response status code of the interface, these changes will be included in the second interface test information); the updated security requirements (any changes regarding authentication and authorization requirements); the updated business rules (updates to the interface business logic), and version information, etc.

[0071] Furthermore, it should be noted that the second interface test information refers to the interface test information obtained after parsing the document to be parsed for the most recent version before synchronization, including the interface definition, such as the path (URL) of the interface, the HTTP method (such as GET, POST, PUT, DELETE, etc.); the request parameters, including detailed information on path parameters, query parameters, request headers, and request body (payload); the response format: the data structure and type of the interface response, usually including the formats of successful responses and error responses; the expected status code: the expected HTTP status code of the interface response; the security requirements: the authentication and authorization information required by the interface; the business rules: the business logic and rules that the interface should follow; the version information: the API version to which the interface belongs, which is not restricted here and can be set according to the actual situation.

[0072] Furthermore, the preset database refers to a database specifically used to store interface test information, in order to shorten the file detection time and information acquisition time. It can be understood that if the document to be parsed is not parsed for the first time, it means that interface test information has been generated during the previous parsing process. Therefore, it is necessary to compare the newly generated interface test information (i.e., the first interface test information) with the previously generated interface test information (i.e., the second interface test information) to determine the updated information elements in the document. Among them, since the interface test information generated by parsing is stored in the preset database every time the document is parsed, the second interface test information can be directly obtained quickly through the preset database for subsequent information comparison.

[0073] Specifically, perform document parsing on the document to be parsed to obtain first interface test information. In one embodiment, use a Python library to read the content of a Swagger JSON / YAML file, and then extract information from the read file content. For example, through built-in Python functions, a preset parsing function (which needs to traverse the parsed data structure), and a preset storage function (in this function, the storage file path will be defined, and the Python library will be used to store the extracted first interface test information in an independent file for subsequent document comparison to determine whether the document to be parsed has changed, that is, whether synchronization is required) to extract and store the first interface test information. For reference, see Figure 2 , Figure 2 FIG. Figure 2 is a schematic flowchart of the brief process of document parsing provided for the interface test method of this application. Among them, the preset parsing function and the preset storage function can be written and set according to actual functions, which are not limited here.

[0074] Further, according to the file address where the interface test information was previously stored and the version number information, obtain the second interface test information corresponding to the document to be parsed in the preset database, that is, obtain the interface test information of the latest version before synchronization, and use it as the second interface test information.

[0075] Step S22: Compare the first interface test information with the second interface test information;

[0076] Specifically, compare the first interface test information with the second interface test information. For example, implement file comparison by looping and comparing the corresponding API detailed data in the two files, which is not limited here.

[0077] Step S23: If the comparison is inconsistent, synchronize each of the first test cases based on the first interface test information and the second interface test information to obtain a number of second test cases.

[0078] Specifically, if the comparison is inconsistent, determine a number of interfaces to be synchronized, the synchronization type and synchronization content corresponding to each of the interfaces to be synchronized based on the first interface test information and the second interface test information, and then find the first test cases corresponding to each of the interfaces to be synchronized, so as to synchronize the first test cases corresponding to each of the interfaces to be synchronized based on the synchronization type and the synchronization content to obtain a number of second test cases.

[0079] Additionally, if the comparison is consistent, determine that there is no need to synchronize and update the test cases this time, and end the execution. For reference, see Figure 3 , Figure 3 FIG. Figure 3 is a schematic flowchart of the brief process of interface test information comparison provided for the interface test method of this application.

[0080] In this embodiment, if the document to be parsed is not parsed for the first time, the document to be parsed is parsed to obtain first interface test information, and second interface test information corresponding to the document to be parsed in the preset database is obtained. Then, the first interface test information is compared with the second interface test information. Thus, if the comparison is inconsistent, based on the first interface test information and the second interface test information, each of the first test cases is synchronized to obtain a number of second test cases. Furthermore, it realizes the automatic detection of changes in the interface document and updates the test cases, reduces the workload of manually updating the test cases, and ensures that the test cases are always consistent with the interface document, avoiding incomplete test coverage caused by the document being updated while the test cases are not updated. Therefore, it improves the document synchronization response speed, maintains the consistency between the interface document and the test cases, and further improves the usability and accuracy of the test cases.

[0081] In a feasible implementation manner, the step of synchronizing each of the first test cases based on the first interface test information and the second interface test information to obtain a number of second test cases includes:

[0082] Step S31, based on the first interface test information and the second interface test information, determine a number of interfaces to be synchronized, and the synchronization type and synchronization content corresponding to each of the interfaces to be synchronized;

[0083] It should be noted that the interface to be synchronized refers to the API interface for which the corresponding test case needs to be updated after the Swagger document (or other API description files) is updated, so as to ensure that the test case can reflect the latest status and behavior of the interface.

[0084] Furthermore, it should be noted that the synchronization type refers to the category of interface changes, which is used to determine what type of update needs to be made to the test case, including: new interface: an interface newly added in the document, for which a new test case needs to be created; modified interface: the interface definition (such as parameters, response structure) has changed, and the existing test case needs to be updated; deleted interface: the interface is removed, and the corresponding test case needs to be deleted or disabled; path change: the URL path of the interface has changed, and the URL in the test case needs to be updated; parameter change: the request parameters of the interface have changed, and the parameters in the test case need to be updated; response change: the response data structure or status code of the interface has changed, and the expected response in the test case needs to be updated. There is no limitation here.

[0085] Furthermore, the synchronization content refers to the specific change details when synchronization is achieved, which is used to guide how to update test cases to match the latest definition of the interface, including: adding new parameters: new parameters need to be added to the test cases; parameter value change: the parameter values in the test cases need to be updated; adding new response fields: new expected response fields need to be added to the test cases; response field value change: the expected response field values in the test cases need to be updated; status code change: the expected status codes in the test cases need to be updated; request method change: the request methods in the test cases need to be updated; security requirement change: the authentication and authorization information in the test cases need to be updated, which is not limited here.

[0086] Specifically, based on the comparison result of the first interface test information and the second interface test information, several interfaces to be synchronized, the corresponding synchronization types and synchronization content of each interface to be synchronized are determined.

[0087] Step S32, search for the first test cases corresponding to each interface to be synchronized;

[0088] Specifically, search for the first test cases corresponding to each interface to be synchronized to accurately identify interface changes, determine the test cases that need to be synchronized, avoid unnecessary synchronization updates, and reduce resource waste.

[0089] Step S33, synchronize the first test cases corresponding to each interface to be synchronized based on the synchronization type and the synchronization content, and obtain several second test cases.

[0090] Specifically, synchronize the first test cases corresponding to each interface to be synchronized based on the synchronization type and the synchronization content, and obtain several second test cases. For example, for the interface to be synchronized of the modification type, first directly search for the first test case through the file name corresponding to the interface to be synchronized, delete its file, and then call the method of dynamically generating test cases (using the API data modified this time (i.e., the synchronization content) as a parameter) to write, generate and store the second test case; for the interface to be synchronized of the addition type, directly call the method of dynamically generating test cases to write, generate and store the second test case; for the interface to be synchronized of the deletion type, directly search for the first test case through the file name corresponding to the interface to be synchronized and delete the corresponding first test case.

[0091] In this embodiment, based on the first interface test information and the second interface test information, several interfaces to be synchronized and the corresponding synchronization types and synchronization contents of each interface to be synchronized are determined. Then, the first test cases corresponding to each interface to be synchronized are searched. Based on the synchronization types and the synchronization contents, the first test cases corresponding to each interface to be synchronized are synchronized to obtain several second test cases. Further, the interface changes are accurately identified, and the test cases that need to be synchronized are determined, avoiding unnecessary synchronization updates, thereby improving the synchronization efficiency. At the same time, it is ensured that the test cases reflect the latest status of the interface document in a timely manner, improving the accuracy, reliability and test coverage of the test, ensuring that all changed interfaces are covered by the corresponding test cases, and then maintaining the consistency between the interface document and the test cases, improving the efficiency, accuracy and adaptability of the test, accelerating the speed of software development and deployment, and at the same time reducing costs and risks.

[0092] In a feasible implementation manner, the judging whether the document to be parsed is parsed for the first time includes:

[0093] Step S41, obtain a detection script;

[0094] It should be noted that the detection script refers to an automated script or program whose function is to check and determine specific conditions or states, and is used to check whether there is a file corresponding to the second interface test information in a preset database.

[0095] Specifically, obtain a detection script, and the detection script can be written in programming languages such as Python, Bash or PowerShell to achieve accessing and checking the status of the file system, which is not limited here.

[0096] Step S42, based on the detection script, detect whether there is a relevant file corresponding to the second interface test information in the preset database;

[0097] It should be noted that the preset database refers to a database specifically used to store the interface test information generated after parsing the document to shorten the file detection time. The relevant file refers to a file directly related to the second interface test information.

[0098] Specifically, use the detection script to detect whether there is a relevant file corresponding to the second interface test information in the preset database. For example, whether there is a relevant file of the interface test information of the api-related data that has been parsed and extracted.

[0099] Understandably, from the parsing steps of the document to be parsed, after parsing the document to be parsed, the interface test information can be stored through a preset storage function (in this function, the storage file path is defined, and the first interface test information extracted is stored in an independent file using the python library for subsequent document comparison to determine whether the document to be parsed has changed, that is, whether synchronization is required). Therefore, if it has not been parsed, there will be no relevant files corresponding to the second interface test information stored in the preset database. Then, the existence of relevant files indicates that it has been parsed before, that is, the document to be parsed is not being parsed for the first time.

[0100] Step S43, if not, then determine that the document to be parsed is being parsed for the first time.

[0101] In this embodiment, by obtaining the detection script, and then based on the detection script, detecting whether there are relevant files corresponding to the second interface test information in the preset database. Thus, if not, it is determined that the document to be parsed is being parsed for the first time. Furthermore, by judging whether the document to be parsed is being parsed for the first time, unnecessary synchronization updates are avoided, thereby improving the efficiency and accuracy of document processing, accelerating the iteration speed of software development and testing, and at the same time reducing waste of computing resources.

[0102] In a feasible implementation manner, after obtaining the document to be parsed and judging whether the document to be parsed is being parsed for the first time, it further includes:

[0103] Step S51, if the document to be parsed is being parsed for the first time, then perform document parsing on the document to be parsed to obtain the second interface test information, and store the second interface test information in the preset database;

[0104] Specifically, if the document to be parsed is being parsed for the first time, then perform document parsing on the document to be parsed to obtain the second interface test information. The generation process of the first interface test information can be referred to and will not be elaborated here. Further, store the second interface test information in the preset database for subsequent determination of whether the document to be parsed is being parsed for the first time and for synchronization update of non-first-parsed documents.

[0105] Step S52, determine several interface information in the second interface test information;

[0106] It should be noted that the interface information refers to the detailed description extracted from the document to be parsed (such as a Swagger document), including various components of the interface, such as the interface path (Endpoint), HTTP method, request parameters, etc., which are not limited here.

[0107] Specifically, several interface information in the second interface test information is determined, that is, multiple interfaces and interface information involved in the second interface test information are extracted, divided, and grouped to obtain several interface information, so as to ensure that each interface has a corresponding test case and improve the test case coverage rate.

[0108] Step S53: Based on each of the interface information and a preset test case template, several of the first test cases are generated.

[0109] It should be noted that the preset test case template refers to a template defined in advance for generating test cases. The preset test case template includes the basic structure of the test case and some placeholders for filling in specific interface information later, including the test case name (usually named based on the interface name and method), test steps, expected results (defining the expected results after executing the test steps, including the status code and response content), request template (including the template of the request URL, method, header information, parameters, and request body), response verification (used to verify whether the interface response meets the expectations, including assertions (expected status code)), exception handling (defining how to handle exceptions during test execution), placeholders (used to insert specific interface information, such as path parameters, query parameters, etc.). The preset test case template can be adjusted in detail according to different projects and is not limited here.

[0110] Specifically, based on each of the interface information and the preset test case template, several of the first test cases are generated. In one embodiment, a Python script is used to read each of the interface information parsed from the Swagger document, and the Jinja2 template engine is used to fill each of the interface information into the placeholders in the preset test case template, thereby generating the first test case corresponding to each interface. Among them, the Python script can reference the interface information in the form of passing parameters, and generate the final test case through steps such as setting the Jinja2 (a template engine in Python) environment, loading the test case template of the previous step, and traversing and filling, and save the first test case as a separate file for use case management. Reference can be made to Figure 4 , Figure 4 which provides a schematic diagram of the brief process for test case generation of the interface test method of this application, so as to quickly generate test cases that meet the specific test framework and project requirements, while maintaining the consistency and standardization of the test cases, to achieve the automatic creation of test cases for each interface, thereby improving the efficiency and accuracy of testing.

[0111] In this embodiment, if so, the to-be-parsed document is parsed to obtain second interface test information, and then several interface information in the second interface test information is determined. Then, based on each piece of the interface information and a preset test case template, several of the first test cases are generated. Furthermore, through an automated process, the time for manually writing test cases is greatly shortened, human errors are reduced, and the efficiency of test preparation work is significantly improved. Thus, the accuracy and consistency of test cases are improved, and it is ensured that all defined interfaces are tested, improving test coverage.

[0112] In a feasible implementation manner, before testing the target interface based on each of the second test cases to generate an interface test result, the following is further included:

[0113] Step S61, obtain user requirements, and based on the user requirements, construct a test trigger;

[0114] It should be noted that the user requirements refer to the expectations and requirements of the user regarding interface testing, such as requirements for performing interface testing at regular intervals, etc., which are not limited here. The test trigger refers to a mechanism or condition for automatically executing tests, used to trigger the execution of tests according to specific events or conditions, such as a timing trigger, so as to automatically execute tests at specific time intervals or specific time points, for example, execute a test once every day at midnight.

[0115] Specifically, obtain user requirements, and based on the user requirements, construct a test trigger. In one embodiment, configure a Pipeline or Freestyle project in Jenkins, and specify the repository address of the use case generation and update script module. Then, for the user requirements, construct a test trigger (the trigger only needs to configure the trigger rule in Jenkins). For example, the test trigger for executing the test can be selected as a timing trigger, and trigger the test trigger according to the specified time interval or specific time point to execute the interface test task. Additionally, a synchronization update trigger can also be constructed according to the synchronization update requirements in the user requirements, so that once the project under test (such as the to-be-parsed document and the target interface, etc.) changes, the synchronization update trigger will be triggered to execute the update script, thereby ensuring the timeliness and accuracy of test case synchronization. Reference can be made to Figure 5 , Figure 5 which is a brief flow schematic diagram of trigger triggering provided for the interface test method of this application.

[0116] Step S62, detect whether to test the target interface through the test trigger;

[0117] Specifically, detect whether to test the target interface through the test trigger. For example, determine whether to test the target interface according to the trigger time of the test trigger.

[0118] Step S63, if so, based on each of the second test cases, test the target interface to generate the interface test result.

[0119] Specifically, if so, based on each of the second test cases, test the target interface to generate the interface test result; if not, continue to detect whether to test the target interface through the test trigger.

[0120] In this embodiment, by obtaining user requirements and constructing a test trigger based on the user requirements, and then detecting whether to test the target interface through the test trigger. Thus, if so, based on each of the second test cases, test the target interface to generate the interface test result. Furthermore, the test trigger is flexibly constructed according to user requirements to adapt to different test scenarios and conditions, and the test process is automatically triggered by constructing the test trigger without manual participation, thereby reducing the need for manual test triggering and improving the speed and frequency of test execution.

[0121] In a feasible implementation manner, the testing the target interface based on each of the second test cases to generate an interface test result includes:

[0122] Step S71, determine the second test case corresponding to the target interface in each of the second test cases;

[0123] Specifically, determine the second test case corresponding to the target interface in each of the second test cases to narrow down the test scope, ensure that only the test cases related to the target interface are executed, improve the pertinence and efficiency of the test, and avoid waste of computing resources.

[0124] Step S72, based on the second test case corresponding to the target interface, test the target interface to obtain interface test data;

[0125] Specifically, based on the second test case corresponding to the target interface, test the target interface to obtain interface test data. For example, according to the second test case corresponding to the target interface, write a Jenkinsfile or configuration script for test case execution, and then test the target interface according to the script to obtain interface test data.

[0126] Step S73, parse the interface test data to generate the interface test result.

[0127] Specifically, a parsing script is used to analyze these interface test data. The parsing process includes checking whether the response status code meets the expectation, verifying whether the response body data structure and content match the preset pattern or value, and recording the response time to evaluate the performance, etc. Thus, according to the parsing results, interface test results are generated, clearly showing whether each test case passes and the specific reasons for any failed test cases, and further providing in-depth insights into the interface quality and performance for the development team to help the development team make corresponding optimization and repair decisions.

[0128] In addition, the interface test results are pushed to the development team members. The pushing methods include email, APP notifications, and applets, etc., and support specifying information such as the mail server, sender, recipient, etc. In addition, conditions for triggering the pushing of interface test results can also be set, such as build failure, test pass rate lower than a certain threshold, etc., which are not restricted here and can be set according to the actual situation.

[0129] In this embodiment, by determining the second test cases corresponding to the target interface in each of the second test cases, and then based on the second test cases corresponding to the target interface, testing the target interface to obtain interface test data, thereby parsing the interface test data to generate the interface test results, further ensuring that only the test cases related to the target interface are executed, improving the pertinence and efficiency of testing, and at the same time reducing the workload of manually writing test reports by automatically generating test results, and improving the speed and consistency of report generation.

[0130] Exemplarily, to help understand the implementation process of the interface test method, please refer to Figure 6 , Figure 6 which is a brief flow chart example provided for the interface test method of this application.

[0131] Specifically, this flow chart describes a process of automatic test case generation and execution, which involves the parsing of Swagger documents and the triggering of Jenkins job modules, and involves the use case generation and update script module and the Jenkins job module.

[0132] First, the system determines whether to parse the Swagger document through the use case generation and update script module to obtain detailed information about the API through the trigger of the Jenkins job module. Further, if so, it is determined whether it is the first time to parse the Swagger document. If this is the first time to parse the Swagger document, the system will generate automatic test cases; if it is not the first time to parse, the system will synchronize the existing test cases. In either case, a set of automatic test cases will finally be obtained.

[0133] Furthermore, the trigger in the Jenkins job module is used to determine whether these test cases need to be executed. If the conditions are met, the test cases will be executed to generate interface test data, and detailed interface test results will be generated based on the interface test data, thereby realizing the automated generation, synchronous update, and execution of test cases through the entire process, ensuring the timeliness and accuracy of API testing, and improving the efficiency of software development and testing.

[0134] It should be noted that the examples in the figures are only for understanding the present application and do not constitute a limitation on the interface testing method of the present application. Based on this technical concept, more forms of simple transformation are within the protection scope of the present application.

[0135] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0136] The present application also provides an interface testing device. Please refer to Figure 7 and the interface testing device includes:

[0137] An acquisition module 71, configured to acquire a document to be parsed and determine whether the document to be parsed is parsed for the first time;

[0138] A synchronization module 72, configured to synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases if the document to be parsed is not parsed for the first time;

[0139] A generation module 73, configured to test a target interface based on each of the second test cases and generate an interface test result.

[0140] The interface testing device is further configured to:

[0141] Parse the document to be parsed to obtain first interface test information, and acquire second interface test information corresponding to the document to be parsed;

[0142] Compare the first interface test information with the second interface test information;

[0143] If the comparison is inconsistent, synchronize each of the first test cases based on the first interface test information and the second interface test information to obtain a plurality of the second test cases.

[0144] The interface testing device is further configured to:

[0145] Based on the first interface test information and the second interface test information, determine a plurality of interfaces to be synchronized, and the synchronization type and synchronization content corresponding to each of the interfaces to be synchronized;

[0146] Find the first test case corresponding to each of the to-be-synchronized interfaces;

[0147] Based on the synchronization type and the synchronization content, synchronize the first test cases corresponding to each of the to-be-synchronized interfaces to obtain a number of the second test cases.

[0148] The interface testing device is further configured to:

[0149] Obtain a detection script;

[0150] Based on the detection script, detect whether there is a relevant file corresponding to the second interface test information in a preset database;

[0151] If not, determine that the to-be-parsed document is parsed for the first time.

[0152] The interface testing device is further configured to:

[0153] If so, perform document parsing on the to-be-parsed document to obtain second interface test information;

[0154] Determine a number of interface information in the second interface test information;

[0155] Based on each of the interface information and a preset test case template, generate a number of the first test cases.

[0156] The interface testing device is further configured to:

[0157] Obtain user requirements and construct a test trigger based on the user requirements;

[0158] Detect whether to test the target interface through the test trigger;

[0159] If so, based on each of the second test cases, test the target interface to generate the interface test result.

[0160] The interface testing device is further configured to:

[0161] Determine the second test case corresponding to the target interface in each of the second test cases;

[0162] Based on the second test case corresponding to the target interface, test the target interface to obtain interface test data;

[0163] Parse the interface test data to generate the interface test result.

[0164] The interface testing device provided by this application adopts the interface testing method in the above embodiment and can solve the technical problems in the background art. Compared with the prior art, the beneficial effects of the interface testing device provided by this application are the same as those of the interface testing method provided by the above embodiment, and the other technical features in the interface testing device are the same as the features disclosed in the method of the above embodiment, which will not be elaborated here.

[0165] This application provides an interface testing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the interface testing method in the first embodiment above.

[0166] Refer to the following Figure 8 , which shows a schematic structural diagram of an interface testing device suitable for implementing the embodiments of this application. The interface testing device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The interface testing device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of this application.

[0167] As Figure 8As shown, the interface test device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM: Read Only Memory) 1002 or the program loaded from the storage device 1003 into the random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the interface test device are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. The input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the interface test device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows an interface test device with various systems, it should be understood that it is not required to implement or have all the shown systems. More or fewer systems can be alternatively implemented or had.

[0168] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above functions defined in the methods of the embodiments disclosed in the present application are executed.

[0169] The interface test device provided by the present application adopts the interface test method in the above embodiments and can solve the technical problems in the background art. Compared with the prior art, the beneficial effects of the interface test device provided by the present application are the same as those of the interface test method provided by the above embodiments, and the other technical features in the interface test device are the same as those disclosed in the method of the previous embodiment, and will not be elaborated here.

[0170] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.

[0171] As described above, the above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application, and all should be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

[0172] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the interface test method in the above embodiments.

[0173] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or combined with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0174] The above computer-readable storage medium can be included in the interface test device; or it can exist independently without being assembled into the interface test device.

[0175] The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed by the interface test device, the interface test device is caused to:

[0176] Obtain the document to be parsed and determine whether the document to be parsed is being parsed for the first time;

[0177] If not, synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases;

[0178] Based on each of the second test cases, test the target interface to generate an interface test result.

[0179] Computer program code for performing the operations of the present application may be written in one or more programming languages or combinations thereof. The above programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partially on the user's computer, execute as a stand-alone software package, execute partially on the user's computer and partially on a remote computer, or execute entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0180] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that, in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0181] The modules described in the embodiments of the present application may be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.

[0182] The readable storage medium provided by this application is a computer-readable storage medium. The computer-readable storage medium stores computer-readable program instructions (i.e., computer programs) for executing the above interface test method, and can solve the technical problems in the background art. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by this application are the same as those of the interface test method provided by the above embodiments, and will not be elaborated here.

[0183] An embodiment of this application provides a computer program product, including a computer program, and the steps of the above interface test method are implemented when the computer program is executed by a processor.

[0184] The computer program product provided by this application can solve the technical problems in the background art. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiments of this application are the same as those of the interface test method provided by the above embodiments, and will not be elaborated here.

[0185] The above are only some embodiments of this application, and do not limit the patent scope of this application accordingly. Any equivalent structural transformation made by using the content of the specification and drawings of this application under the technical concept of this application, or any direct / indirect application in other related technical fields, is included in the patent protection scope of this application.

Claims

1. An interface testing method, characterized in that, It includes: Obtain the document to be parsed, and determine whether the document to be parsed is parsed for the first time; If not, synchronize a number of first test cases corresponding to the document to be parsed to obtain a number of second test cases; Based on each of the second test cases, test the target interface to generate an interface test result.

2. The interface testing method according to claim 1, wherein The "if not" then synchronize a number of first test cases corresponding to the document to be parsed to obtain a number of second test cases, including: If the document to be parsed is not parsed for the first time, perform document parsing on the document to be parsed to obtain first interface test information, and obtain second interface test information corresponding to the document to be parsed in the preset database; Compare the first interface test information with the second interface test information; If the comparison is inconsistent, synchronize each of the first test cases based on the first interface test information and the second interface test information to obtain a number of the second test cases.

3. The interface testing method according to claim 2, characterized in that, The synchronizing each of the first test cases based on the first interface test information and the second interface test information to obtain a number of the second test cases includes: Based on the first interface test information and the second interface test information, determine a number of interfaces to be synchronized and the synchronization type and synchronization content corresponding to each of the interfaces to be synchronized; Search for the first test cases corresponding to each of the interfaces to be synchronized; Based on the synchronization type and the synchronization content, synchronize the first test cases corresponding to each of the interfaces to be synchronized to obtain a number of the second test cases.

4. The interface testing method according to claim 1, wherein The determining whether the document to be parsed is parsed for the first time includes: Obtain a detection script; Based on the detection script, detect whether there are relevant files corresponding to the second interface test information in the preset database; If not, determine that the document to be parsed is parsed for the first time.

5. The interface testing method according to claim 1, wherein After the obtaining the document to be parsed and determining whether the document to be parsed is parsed for the first time, it further includes: If the document to be parsed is parsed for the first time, perform document parsing on the document to be parsed to obtain second interface test information, and store the second interface test information in the preset database; Determine a number of interface information in the second interface test information; Based on each of the interface information and a preset test case template, generate a number of the first test cases.

6. The interface testing method according to claim 1, characterized in that, Before the testing the target interface based on each of the second test cases to generate an interface test result, it further includes: Obtain user requirements, and based on the user requirements, construct a test trigger; Detect whether to test the target interface through the test trigger; If so, test the target interface based on each of the second test cases to generate the interface test result.

7. The interface testing method according to claim 1, wherein The testing the target interface based on each of the second test cases to generate an interface test result includes: Determine the second test cases corresponding to the target interface in each of the second test cases; Based on the second test cases corresponding to the target interface, test the target interface to obtain interface test data; Parse the interface test data to generate the interface test result.

8. An interface testing device, characterized in that, It includes: An acquisition module, configured to acquire a document to be parsed and determine whether the document to be parsed is parsed for the first time; A synchronization module, configured to synchronize a plurality of first test cases corresponding to the document to be parsed to obtain a plurality of second test cases if the document to be parsed is not parsed for the first time; A generation module, configured to test a target interface based on each of the second test cases and generate an interface test result.

9. An interface testing device, characterized in that, The interface testing device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, where the computer program is configured to implement the steps of the interface testing method according to any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the interface testing method according to any one of claims 1 to 7 are implemented.