Test case generation method, device, electronic device, medium and product
By receiving test case generation requests, using packet capture technology to obtain and preprocess API interface information, generate test cases, solving the problem of low efficiency in manual writing test cases, realizing automatic generation of test cases, and improving efficiency.
Patent Information
- Application Number
- CN202411981499.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-08
AI Technical Summary
With the increase in the number of interfaces and the complexity of business logic, the workload of manually writing test cases is huge and there is a problem of inefficiency.
By receiving test case generation requests, determine the corresponding API for the target interface identification, use packet capture technology to obtain the interface information of the API execution call, perform data preprocessing, and generate target test cases.
Automatically obtain target interface information, automatically generate test cases, significantly reduce manual operations, and improve the generation efficiency of test cases.
Smart Images

Figure CN119782184A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of automation technology, and in particular to a method, device, electronic device, medium and product for generating a test case. Background Art
[0002] As the complexity of modern software systems continues to increase, interfaces have become the core of inter-system communication. Interfaces can be used for interaction between internal modules and are also widely used for integration with external systems. Therefore, it is crucial to ensure the stability and performance of APIs. Interface testing, as a key means to verify interface functionality, performance, and security, has become an indispensable part of the software development process.
[0003] In related technologies, interface testing mainly relies on manually writing test cases. Testers write test cases one by one according to interface documents and verify whether each interface works normally by executing the test cases.
[0004] However, with the increase in the number of interfaces and the complexity of business logic, the workload of manually writing test cases is huge and there is a problem of low efficiency. Summary of the invention
[0005] The present application provides a test case generation method, device, electronic device, medium and product to improve the efficiency of generating test cases.
[0006] In a first aspect, the present application provides a method for generating a test case, comprising: receiving a test case generation request, the test case generation request comprising multiple target interface identifiers; determining, based on the test case generation request, multiple target application programming interfaces API corresponding to the multiple target interface identifiers, and obtaining, through packet capture technology, target interface information for executing calls to the multiple target APIs; performing data preprocessing on the target interface information to obtain target message data; and generating a target test case based on the target message data.
[0007] Optionally, the method as described above generates a target test case based on the target message data, including: determining multiple target call data corresponding to the multiple target APIs from the target message data, and generating multiple single-interface test cases corresponding to the multiple target APIs based on the multiple target call data; determining association information of multiple associated APIs from the target message data, and generating scenario test cases corresponding to the multiple associated APIs based on the target message data and the association information; determining that the target test case includes the single-interface test case and the scenario test case.
[0008] Optionally, in the method as described above, the test case generation request also includes a target verification strategy, and the target verification strategy includes at least one of the following: permission verification, field type verification, mandatory input verification, missing field verification, boundary value verification, or abnormal input verification; for any target API; based on the multiple target call data, a single-interface test case corresponding to the target API is generated, including: based on the target verification strategy, determining a target test case template, and the target test case template covers the target verification strategy; determining the first request information and the first response information of the target API from the multiple target call data; and generating the single-interface test case based on the first request information, the first response information, and the target test case template.
[0009] Optionally, the method as described above generates scenario test cases corresponding to the multiple associated APIs based on the target message data and the associated information, including: determining multiple second request information and multiple second response information corresponding to the multiple associated APIs from the target message data; determining the scenario association order between the multiple associated APIs based on the associated information; and generating the scenario test case based on the multiple second request information, the multiple first response information, and the scenario association order.
[0010] Optionally, the method as described above performs data preprocessing on the target interface information to obtain target message data, including: performing a first processing on the target interface information to obtain intermediate interface information, the first processing including at least one of the following: format conversion, port filtering, or information sorting; determining that the multiple target APIs correspond to multiple interface paths and multiple interface methods; obtaining related information from an interface document management platform based on the multiple interface paths and the multiple interface methods; and generating the target message data based on the target interface information and the related information.
[0011] Optionally, as described above, the method further includes: obtaining multiple request entry information corresponding to the multiple target APIs from a target library; performing test processing on the multiple target APIs according to the target test cases and the multiple request entry information to obtain multiple test results corresponding to the multiple target APIs; analyzing and processing the multiple test results to determine multiple target coverage rates corresponding to the multiple target APIs; if the multiple target coverage rates are all greater than a coverage rate threshold, generating a test report based on the multiple test results and the multiple target coverage rates; if any target coverage rate is less than or equal to the coverage rate threshold, regenerating the target test case.
[0012] In the second aspect, the present application provides a test case generation device, including: a receiving module, used to receive a test case generation request, the test case generation request including multiple target interface identifiers; an acquisition module, used to determine multiple target application programming interfaces API corresponding to the multiple target interface identifiers according to the test case generation request, and obtain target interface information of the multiple target API execution calls through packet capture technology; a preprocessing module, used to perform data preprocessing on the target interface information to obtain target message data; a generation module, used to generate a target test case based on the target message data.
[0013] Optionally, in the device as described above, the generation module is specifically used to determine multiple target call data corresponding to the multiple target APIs from the target message data, and generate multiple single-interface test cases corresponding to the multiple target APIs based on the multiple target call data; the generation module is also specifically used to determine association information of multiple associated APIs from the target message data, and generate scenario test cases corresponding to the multiple associated APIs based on the target message data and the association information; the generation module is also specifically used to determine that the target test case includes the single-interface test case and the scenario test case.
[0014] Optionally, in the device as described above, the test case generation request also includes a target verification strategy, and the target verification strategy includes at least one of the following: permission verification, field type verification, mandatory input verification, missing field verification, boundary value verification, or abnormal input verification; for any target API; the generation module is specifically used to determine the target test case template according to the target verification strategy, and the target test case template covers the target verification strategy; the generation module is also specifically used to determine the first request information and the first response information of the target API from the multiple target call data; the generation module is also specifically used to generate the single interface test case according to the first request information, the first response information, and the target test case template.
[0015] Optionally, in the device as described above, the generation module is specifically used to determine, from the target message data, multiple second request information and multiple second response information corresponding to the multiple associated APIs; the generation module is also specifically used to determine the scenario association order between the multiple associated APIs based on the association information; the generation module is also specifically used to generate the scenario test case based on the multiple second request information, the multiple first response information, and the scenario association order.
[0016] Optionally, as described above, the device further includes: an association module, used to perform a first processing on the target interface information to obtain intermediate interface information, the first processing including at least one of the following: format conversion, port filtering, or information sorting; the association module is also used to determine that the multiple target APIs correspond to multiple interface paths and multiple interface methods; the association module is also used to obtain association information from an interface document management platform based on the multiple interface paths and the multiple interface methods; the association module is also used to generate the target message data based on the target interface information and the association information.
[0017] Optionally, as described above, the device further includes: a verification module, used to obtain multiple request entry information corresponding to the multiple target APIs from a target library; the verification module is also used to perform test processing on the multiple target APIs according to the target test cases and the multiple request entry information, and obtain multiple test results corresponding to the multiple target APIs; the verification module is also used to analyze and process the multiple test results to determine multiple target coverage rates corresponding to the multiple target APIs; the verification module is also used to generate a test report based on the multiple test results and the multiple target coverage rates if the multiple target coverage rates are all greater than a coverage rate threshold; the verification module is also used to regenerate the target test case if any target coverage rate is less than or equal to the coverage rate threshold.
[0018] In a third aspect, the present application provides an electronic device comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement any method described in the first aspect.
[0019] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by a processor as described in any one of the methods in the first aspect.
[0020] In a fifth aspect, the present application provides a computer program product, comprising a computer program, wherein the computer program is executed by a processor as in any one of the methods in the first aspect.
[0021] The test case generation method, device, electronic device, medium and product provided in the present application include: receiving a test case generation request, wherein the test case generation request includes multiple target interface identifiers; determining multiple target application programming interfaces API corresponding to the multiple target interface identifiers according to the test case generation request, and obtaining target interface information for executing calls of the multiple target APIs through packet capture technology; performing data preprocessing on the target interface information to obtain target message data; and generating target test cases according to the target message data. The above scheme automatically obtains target interface information and automatically generates target test cases based on the target interface information, which can effectively reduce manual operations and thus improve the efficiency of test case generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0023] Figure 1 A schematic diagram of an application scenario of a method for generating a test case provided in an embodiment of the present application;
[0024] Figure 2 A flowchart of a method for generating a test case provided in an embodiment of the present application;
[0025] Figure 3 A flowchart of a method for generating a test case provided in an embodiment of the present application;
[0026] Figure 4 A schematic diagram of generating target message data provided by an embodiment of the present application;
[0027] Figure 5 A schematic diagram of generating a single interface test case provided in an embodiment of the present application;
[0028] Figure 6 A schematic diagram of generating scenario test cases provided in an embodiment of the present application;
[0029] Figure 7 A schematic diagram of the structure of a test case generation device provided in an embodiment of the present application;
[0030] Figure 8 A schematic diagram of the structure of a test case generation device provided in an embodiment of the present application;
[0031] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0032] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0033] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0034] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0035] It should be noted that the method, device, electronic device, medium and product for generating test cases of the present application can be used in the field of automation technology, and can also be used in any field other than automation. The application field of the method, device, electronic device, medium and product for generating test cases of the present application is not limited.
[0036] Figure 1 A schematic diagram of an application scenario of a test case generation method provided in an embodiment of the present application is given as an example in combination with the illustrated scenario: System 1 communicates with System 2 through an interface, and System 1 and System 2 can send and receive data to each other to achieve two-way communication.
[0037] Exemplarily, an interface is an abstract concept used to define specifications and protocols of a set of operations or methods, which stipulate how systems, modules or components interact with each other.
[0038] Exemplarily, the specific form of the interface includes the Application Programming Interface (API). API is an interface for communication between different software systems. It defines how to interact with other systems through network requests, usually using HTTP / HTTPS protocols, and the returned data format can be JSON or XML, etc. The core functions of the API include: Request and response: API defines how the client sends requests to the server (such as HTTP methods such as GET, POST, PUT, DELETE, etc.), and how the server returns responses (such as status codes, response bodies). Data format: API usually specifies the data format of requests and responses. The most common formats are JSON and XML. JSON is simple and easy to read. Authentication and authorization: API usually requires authentication and authorization to ensure that only authorized users or systems can access specific functions or data. Version control: API can be updated or modified over time. To ensure compatibility, API usually adopts version control, such as distinguishing different versions of API by version number in URL path or request header.
[0039] Combined with the scenario example, API, as a bridge between different systems, carries a large amount of data transmission and business logic processing. Therefore, the stability, performance and security of API are directly related to the user experience and business success of the entire system.
[0040] In the related art, testers manually write test cases, test the API by executing the test cases, and verify the API based on the test results. Manually writing test cases requires testers to design, code, and debug each test scenario one by one. For complex systems, especially test cases involving multiple parameters, multiple input combinations, and different boundary conditions, writing comprehensive test cases is very time-consuming and there is a problem of low efficiency in generating test cases.
[0041] The method for generating test cases provided in this application is intended to solve the above technical problems in the prior art.
[0042] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0043] Figure 2 A flow chart of a method for generating a test case provided in an embodiment of the present application, the method comprising the following steps:
[0044] S201. Receive a test case generation request, where the test case generation request includes multiple target interface identifiers.
[0045] The target interface identifier is the identifier of the interface specified by the test case generation request, and the test case generation request is used to instruct generation of a corresponding interface test case for the specified interface.
[0046] Among them, interface test cases are small test units used to verify interface functions, performance, security, and compatibility. They usually consist of a set of input data, execution steps, and expected results.
[0047] Optionally, the target interface identifier is a unique identifier, and the corresponding interface can be accurately determined through the target interface identifier.
[0048] S202, generating a request according to the test case, determining multiple target application programming interfaces API corresponding to multiple target interface identifiers, and obtaining target interface information of the multiple target API execution calls through packet capture technology.
[0049] The target API is the API for which the test case is to be generated.
[0050] Exemplarily, the target interface information includes detailed information of the request and response of the target API, specifically including but not limited to at least one of the following: HTTP / HTTPS request, data packet of TCP / IP protocol layer, or payload content, etc.
[0051] Optionally, obtain the target interface information through a packet capture tool or browser recording function.
[0052] Combined with the scenario example, the packet capture technology can automatically capture the complete interface information of the target API. Compared with the manual method, it can avoid omissions and improve the comprehensiveness of the generated test cases.
[0053] S203: Perform data preprocessing on the target interface information to obtain target message data.
[0054] The target interface information is obtained by packet capture technology, which may contain chaotic data or irrelevant data. If a test case is directly generated by the target interface information, the test case may be inaccurate.
[0055] Exemplarily, through preprocessing, the target interface information is converted into structured and standardized target message data, thereby accurately generating a target test case.
[0056] S204: Generate a target test case according to the target message data.
[0057] Among them, the target test case is used to test the target API.
[0058] In the related art, target test cases are generated manually. The present application automatically generates target test cases according to target message data, which can effectively improve the generation efficiency.
[0059] Optionally, a test case is generated according to the target message data, the test case is verified, and the test case that passes the verification is determined as the target test case. It can be understood that the accuracy of the target test case can be ensured through the verification process.
[0060] The test case generation method provided in the embodiment of the present application receives a test case generation request, the test case generation request includes multiple target interface identifiers; according to the test case generation request, multiple target application programming interfaces API corresponding to the multiple target interface identifiers are determined, and the target interface information of the multiple target API execution calls is obtained through packet capture technology; data preprocessing is performed on the target interface information to obtain target message data; and target test cases are generated according to the target message data. The above scheme automatically obtains the target interface information and automatically generates the target test case based on the target interface information, which can effectively reduce manual operations and thus improve the efficiency of test case generation.
[0061] Based on any of the above embodiments, Figure 3 , the detailed process of test case generation is explained.
[0062] Figure 3 The following is a flow chart of a method for generating a test case provided in an embodiment of the present application. Figure 3 As shown, the method includes:
[0063] S301. Receive a test case generation request, where the test case generation request includes multiple target interface identifiers.
[0064] It should be noted that the execution process of S301 refers to S201 and will not be repeated here.
[0065] S302: Generate a request according to the test case, determine multiple target application programming interfaces API corresponding to multiple target interface identifiers, and obtain target interface information of the multiple target API execution calls through packet capture technology.
[0066] It should be noted that the execution process of S302 refers to S202 and will not be repeated here.
[0067] S303: Perform a first process on the target interface information to obtain intermediate interface information.
[0068] The first processing includes at least one of the following: format conversion, port filtering, or information sorting.
[0069] Exemplarily, the format conversion may be converting information of different formats in the target interface information into a unified format. By format conversion, compatibility issues between different formats are avoided, thereby improving the accuracy of the test case.
[0070] For example, port filtering can be to filter out resource requests that do not belong to the backend from the target interface information, such as JavaScript files, images, or CSS files and other front-end resource requests. These front-end resource requests are irrelevant to the back-end API and may increase the complexity of the test case. Through port filtering, it can be ensured that only information related to the target API is retained to avoid irrelevant information interfering with the generation of test cases.
[0071] For example, the information can be sorted in chronological order, which can clearly show the order in which events occur, thereby ensuring that the test cases are executed in the correct order.
[0072] S304: Determine that multiple target APIs correspond to multiple interface paths and multiple interface methods.
[0073] Among them, each target API corresponds to an interface path and an interface method.
[0074] Exemplarily, the interface path is the URL path of the API, which is used to specify the specific resource or operation of the API. The interface method is the method of the HTTP request, which is used to specify the type of operation performed on the resource.
[0075] For example, the interface path and interface method reflect the function and operation type of the API. They have clear semantics, can intuitively express the role of the API, and have strong readability.
[0076] S305. Acquire related information from the interface document management platform according to the multiple interface paths and the multiple interface methods.
[0077] For example, the information obtained through packet capture technology may be missing, such as missing information in fields such as interface name, interface remarks, parameter description, or error code description. Obtaining the missing information associated with the target API from the interface document management platform can enrich the content of the test case.
[0078] Optionally, the associated information is obtained by batch query. It can be understood that for a large amount of information corresponding to a large number of target APIs, batch query can be used to obtain multiple pieces of associated information each time, which can effectively improve the efficiency of obtaining associated information, thereby improving the efficiency of generating test cases.
[0079] S306: Generate target message data according to the target interface information and the associated information.
[0080] Optionally, constructing the target message data includes but is not limited to at least one of the following: constructing a request URL, constructing a request header, constructing a request body, generating boundary values and exception test cases, or generating response verification rules, etc.
[0081] Exemplarily, constructing a request URL may include: concatenating the path and query parameters, combining the static path portion of the target interface with the dynamic path parameters to generate a complete request URL. Processing URL encoding to ensure that all special characters and non-ASCII characters are properly URL encoded to conform to the standard URL format. Constructing a request header may include: adding authentication information, content type, and other necessary request headers according to the requirements in the associated information. Ensuring that the request header conforms to the API specification. Constructing a request body may include: determining the request body format, selecting a suitable structure according to the request body format in the associated information (such as JSON, XML, form data, etc.). Filling in request body parameters, generating reasonable values for each parameter in the request body according to the parameter description in the associated information. Ensuring that the type, format, and constraints of the parameters conform to the requirements of the API. Generating boundary values and exception test cases may include: generating boundary values, generating boundary values (such as minimum value, maximum value, null value, etc.) for each parameter to test the behavior of the API in extreme cases. Generating exception values: generating exception values (such as illegal characters, out-of-range values, etc.) for each parameter to verify the error handling capability of the API. Handle missing parameters and generate request messages that lack certain required parameters to test the API's processing logic for missing parameters. Generating response validation rules may include: Status code validation: Generate validation rules for the response status code based on the status code definition in the associated information to ensure that the API returns the expected status code. Response body validation: Generate validation rules for the response body based on the response body format in the associated information to ensure that the structure and content of the response body meet expectations. Error code validation: Generate validation rules for the error code based on the error code definition in the associated information to ensure that the API returns the correct error information in abnormal situations.
[0082] Next, combine Figure 4 Describe the generation of target message data.
[0083] Figure 4 A schematic diagram of generating target message data provided by an embodiment of the present application. Figure 4As shown, generating target message data includes two main steps. Step 1 is to obtain the target interface information of the target API and perform the first processing to obtain the intermediate interface information. Step 2 is to obtain the associated information from the interface document management platform according to the interface path and interface method of the target API. The target message data is generated according to the intermediate interface information and the associated information.
[0084] Based on the above implementation methods, by acquiring associated information, the content of the target message data can be enriched, thereby improving the accuracy of the test case.
[0085] S307: Determine multiple target call data corresponding to multiple target APIs from the target message data, and generate multiple single-interface test cases corresponding to the multiple target APIs based on the multiple target call data.
[0086] Among them, the single interface test case is a functional test for a single target API. It mainly verifies whether the input, output, status code, or response time of a single target API meets expectations, ensuring that the target API can work correctly in various situations.
[0087] The target call data is the data corresponding to the target API in the target message data.
[0088] A feasible implementation method is to target any target API; a single interface test case corresponding to the target API can be generated by the following method: according to the target verification strategy, a target test case template is determined, and the target test case template covers the target verification strategy; from multiple target call data, the first request information and the first response information of the target API are determined; according to the first request information, the first response information, and the target test case template, a single interface test case is generated.
[0089] Among them, the test case generation request also includes a target verification strategy, and the target verification strategy includes at least one of the following: permission verification, field type verification, mandatory input verification, missing field verification, boundary value verification, or abnormal input verification.
[0090] Next, combine Figure 5 Describes how to generate a single interface test case.
[0091] Figure 5 This is a schematic diagram of generating a single interface test case provided by an embodiment of the present application. Figure 5 As shown, according to the test case generation request, the target verification strategy and the target call strategy are determined. According to the target verification strategy, the corresponding target test case template is determined. According to the target call data, the first request information and the first response information are determined. The first request information and the first response information are filled into the target test case template to generate a single interface test case.
[0092] Exemplarily, permission checking is used to verify whether the target API correctly handles the authentication and authorization mechanisms. Field type checking is used to verify whether the fields in the request body or response body conform to the expected data type (such as string, integer, or Boolean value, etc.). Required input checking is used to verify whether required fields are passed correctly and cannot be empty. Missing field checking is used to verify whether the target API can correctly handle and return reasonable error messages when certain fields are not provided. Boundary value checking is used to verify whether the target API can correctly handle boundary values (such as minimum value, maximum value, empty value, etc.). Abnormal input checking is used to verify whether the target API can correctly handle illegal input (such as out-of-range values, illegal characters, etc.).
[0093] Exemplarily, the target test case template is a predefined structure used to guide how to generate a test case.
[0094] Combined with the scenario example, for example, if the target verification strategy includes permission verification and field type verification, you should select a target test case template that includes these two verification rules. According to the test case generated by the target test case template, you can perform permission verification and field type verification on the target API.
[0095] Exemplarily, the first request information is a valid request of the target API, and the first response information is a valid response of the target API.
[0096] Optionally, the first request information includes information such as a request URL, a request header, or a request body, etc. The first response information includes information such as a response status code, a response header, or a response body, etc.
[0097] Exemplarily, the first request information and the first response information are filled into the target test case template to obtain a single interface test case. By testing the target API through the single interface test case, it can be verified whether the target API can correctly return the expected first response information after inputting the specified first request information under the target verification strategy, thereby obtaining the test result.
[0098] In this feasible implementation, the single interface test cases generated by the clear target verification strategy ensure that the functions and behaviors of the target API are fully tested, covering more scenarios and avoiding missing key test points.
[0099] S308. Determine the association information of multiple associated APIs from the target message data, and generate scenario test cases corresponding to the multiple associated APIs according to the target message data and the association information.
[0100] The scenario interface test case is a test for the combined call of a group of related APIs. It simulates real business scenarios, verifies whether the interaction between multiple related APIs is in line with expectations, and ensures that the entire business process can be executed smoothly.
[0101] Exemplarily, the multiple associated APIs are a group of APIs corresponding to the first scenario.
[0102] A feasible implementation method can generate scenario test cases by the following method: determine multiple second request information and multiple second response information corresponding to multiple associated APIs from the target message data; determine the scenario association order between the multiple associated APIs based on the association information; generate scenario test cases based on the multiple second request information, the multiple first response information, and the scenario association order.
[0103] Optionally, the above test case template solution is also used to generate scenario test cases. It can be understood that the efficiency of generating test cases can be effectively improved through the test case template.
[0104] Next, combine Figure 6 Describes generating scenario test cases.
[0105] Figure 6 This is a schematic diagram of generating scenario test cases provided in an embodiment of the present application. Figure 6 As shown, according to the test case generation request, multiple related APIs are determined. The association information between the multiple related APIs, the second request information of the multiple related APIs, the second response information, and the test case template are determined. According to the association information, the second request information and the second response information are filled into the test case template to generate a scenario test case.
[0106] Exemplarily, the scene association order between multiple associated APIs is the logical order in which the multiple associated APIs are executed when executing a scene service.
[0107] Combined with the scenario example, in the same scenario, there is an execution order between multiple related APIs. For example, the login-related API must be executed before the API for creating an order can be executed.
[0108] Optionally, a dependency graph is constructed based on the association information. The dependency graph includes nodes, edges, and weights. Each API in the dependency graph corresponds to a node. The dependency graph can be used to accurately determine the scene association order between multiple associated APIs.
[0109] In this feasible implementation, the interaction sequence between multiple associated APIs can be simulated through the scenario association sequence, which conforms to the actual business process and thus improves the accuracy of scenario test cases.
[0110] It should be noted that S307 and S308 can be executed simultaneously or in a distributed manner, and this application does not limit the execution order of S307 and S308.
[0111] S309: Determine that the target test cases include single interface test cases and scenario test cases.
[0112] Combined with the scenario example description, single interface test cases and scenario test cases are identified as target test cases, which can not only verify the function of a single API, but also verify the interaction of multiple APIs by simulating scenarios, thereby improving the comprehensiveness of the test cases.
[0113] A feasible implementation method, the test case generation method also includes: obtaining multiple request entry information corresponding to multiple target APIs from a target library; performing test processing on multiple target APIs according to the target test cases and the multiple request entry information to obtain multiple test results corresponding to the multiple target APIs; analyzing and processing the multiple test results to determine multiple target coverage rates corresponding to the multiple target APIs; if the multiple target coverage rates are all greater than the coverage rate threshold, generating a test report based on the multiple test results and the multiple target coverage rates; if any target coverage rate is less than or equal to the coverage rate threshold, regenerating the target test case.
[0114] Among them, the target library is used to encapsulate the request entry of each API to facilitate the maintenance and statistics of API execution status.
[0115] The request entry information includes but is not limited to at least one of the following: API path, HTTP method, request header structure, request body structure, or query parameters, etc. By requesting the entry information, it can be ensured that the calling method is correct, thereby improving the test accuracy.
[0116] The target coverage rate indicates the test coverage of each target API.
[0117] Optionally, the target coverage may include at least one of the following: path coverage, branch coverage, boundary value coverage, or abnormal situation coverage, etc. Through multiple coverages, the test coverage can be evaluated from multiple dimensions, thereby improving the accuracy of the test report.
[0118] Optionally, the data collector is used to collect data such as the number of executions and response time of each interface. The collected data is summarized and printed into a table through the report generator to display information such as the overall coverage rate of the interface, the pass rate, the execution test of each interface, the response time, etc. It can be understood that by automatically generating reports, manual operations can be reduced and the efficiency of generating reports can be improved.
[0119] In this feasible implementation, by verifying the coverage, it is possible to accurately determine whether the test is effective, thereby improving the accuracy of the test.
[0120] Figure 7 A schematic diagram of the structure of a test case generation device provided in an embodiment of the present application. Figure 7 As shown, the test case generation device 70 may include: a receiving module 71, an acquisition module 72, a preprocessing module 73, and a generation module 74, wherein:
[0121] The receiving module 71 is used to receive a test case generation request, where the test case generation request includes multiple target interface identifiers.
[0122] The acquisition module 72 is used to generate a request according to the test case, determine multiple target application programming interfaces API corresponding to multiple target interface identifiers, and obtain target interface information of the multiple target API execution calls through packet capture technology.
[0123] The preprocessing module 73 is used to perform data preprocessing on the target interface information to obtain target message data.
[0124] The generating module 74 is used to generate a target test case according to the target message data.
[0125] Optionally, the receiving module 71 may execute Figure 2 S201 in the embodiment.
[0126] Optionally, the acquisition module 72 may execute Figure 2 S202 in the embodiment.
[0127] Optionally, the preprocessing module 73 may perform Figure 2 S203 in the embodiment.
[0128] Optionally, the generation module 74 may execute Figure 2 S204 in the embodiment.
[0129] It should be noted that the test case generation device shown in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0130] In a possible implementation, the generating module 74 is specifically configured to:
[0131] Determine multiple target call data corresponding to multiple target APIs from the target message data, and generate multiple single interface test cases corresponding to the multiple target APIs according to the multiple target call data;
[0132] Determine the association information of multiple associated APIs from the target message data, and generate scenario test cases corresponding to the multiple associated APIs based on the target message data and the association information;
[0133] The target test cases include single interface test cases and scenario test cases.
[0134] In a possible implementation, the test case generation request further includes a target verification strategy, which includes at least one of the following: permission verification, field type verification, mandatory input verification, missing field verification, boundary value verification, or abnormal input verification; for any target API; a generation module 74 is specifically used to:
[0135] According to the target verification strategy, a target test case template is determined, and the target test case template covers the target verification strategy;
[0136] Determine first request information and first response information of a target API from the plurality of target call data;
[0137] A single interface test case is generated according to the first request information, the first response information, and the target test case template.
[0138] In a possible implementation, the generating module 74 is specifically configured to:
[0139] Determine, from the target message data, a plurality of second request information and a plurality of second response information corresponding to the plurality of associated APIs;
[0140] Determine the scene association order between multiple associated APIs based on the association information;
[0141] A scenario test case is generated according to the multiple second request information, the multiple first response information, and the scenario association sequence.
[0142] Figure 8 A schematic diagram of the structure of a test case generation device provided in an embodiment of the present application. Figure 7 Based on the embodiment shown, Figure 8 As shown, the test case generation device 80 also includes: an association module 75 and a verification module 76, wherein:
[0143] The association module 75 is used to:
[0144] Performing a first process on the target interface information to obtain intermediate interface information, wherein the first process includes at least one of the following: format conversion, port filtering, or information sorting;
[0145] Determine that multiple target APIs correspond to multiple interface paths and multiple interface methods;
[0146] According to multiple interface paths and multiple interface methods, associated information is obtained from the interface document management platform;
[0147] Generate target message data according to target interface information and associated information.
[0148] The verification module 76 is used to:
[0149] Obtain multiple request entry information corresponding to multiple target APIs from the target library;
[0150] According to the target test case and the multiple request entry information, the test processing is performed on the multiple target APIs to obtain multiple test results corresponding to the multiple target APIs;
[0151] Analyze and process multiple test results to determine multiple target coverages corresponding to multiple target APIs;
[0152] If multiple target coverages are all greater than the coverage threshold, a test report is generated based on multiple test results and multiple target coverages;
[0153] If any target coverage is less than or equal to the coverage threshold, the target test case is regenerated.
[0154] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Fig. 9 As shown, the electronic device includes:
[0155] The electronic device includes a processor 291 and a memory 292; it may also include a communication interface 293 and a bus 294. The processor 291, the memory 292, and the communication interface 293 may communicate with each other through the bus 294. The communication interface 293 may be used for information transmission. The processor 291 may call the logic instructions in the memory 292 to execute the method of the above embodiment.
[0156] In addition, the logic instructions in the above-mentioned memory 292 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0157] The memory 292 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the methods in the embodiments of the present application. The processor 291 executes functional applications and data processing by running the software programs, instructions, and modules stored in the memory 292, that is, implementing the methods in the above method embodiments.
[0158] The memory 292 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 292 may include a high-speed random access memory and may also include a non-volatile memory.
[0159] An embodiment of the present application provides a non-temporary computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method as described in the above embodiment.
[0160] An embodiment of the present application provides a computer program product, including a computer program, which implements the method of the above embodiment when the computer program is executed by a processor.
[0161] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0162] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0163] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0164] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0165] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. The processor may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, and an ASIC, etc. The storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory RRAM (Resistive Random Access Memory), a dynamic random access memory DRAM (Dynamic Random Access Memory), a static random access memory SRAM (Static Random-Access Memory), an enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), a high-bandwidth memory HBM (High-Bandwidth Memory), a hybrid memory cube HMC (Hybrid Memory Cube), etc.
[0166] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0167] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0168] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0169] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for generating a test case, characterized in that: include: Receiving a test case generation request, wherein the test case generation request includes a plurality of target interface identifiers; Generate a request according to the test case, determine multiple target application programming interfaces API corresponding to the multiple target interface identifiers, and obtain target interface information of the multiple target API execution calls through packet capture technology; Performing data preprocessing on the target interface information to obtain target message data; Generate a target test case based on the target message data.
2. The method according to claim 1, characterized in that Generate a target test case according to the target message data, including: Determine, from the target message data, multiple target call data corresponding to the multiple target APIs, and generate multiple single-interface test cases corresponding to the multiple target APIs according to the multiple target call data; Determine association information of multiple associated APIs from the target message data, and generate scenario test cases corresponding to the multiple associated APIs based on the target message data and the association information; Determine that the target test case includes the single interface test case and the scenario test case.
3. The method according to claim 2, characterized in that The test case generation request also includes a target verification strategy, and the target verification strategy includes at least one of the following: permission verification, field type verification, mandatory input verification, missing field verification, boundary value verification, or abnormal input verification; For any target API; Generate a single interface test case corresponding to the target API according to the multiple target call data, including: Determine a target test case template according to the target verification strategy, wherein the target test case template covers the target verification strategy; Determining first request information and first response information of the target API from the plurality of target call data; The single-interface test case is generated according to the first request information, the first response information, and the target test case template.
4. The method according to claim 2, characterized in that: Generating scenario test cases corresponding to the multiple associated APIs according to the target message data and the associated information, including: Determine, from the target message data, a plurality of second request information and a plurality of second response information corresponding to the plurality of associated APIs; Determining a scene association order between the multiple associated APIs according to the association information; The scenario test case is generated according to the multiple second request information, the multiple first response information, and the scenario association sequence.
5. The method according to any one of claims 1 to 4, characterized in that Performing data preprocessing on the target interface information to obtain target message data includes: Performing a first process on the target interface information to obtain intermediate interface information, wherein the first process includes at least one of the following: format conversion, port filtering, or information sorting; Determine that the multiple target APIs correspond to multiple interface paths and multiple interface methods; Acquire association information from an interface document management platform according to the multiple interface paths and the multiple interface methods; The target message data is generated according to the target interface information and the associated information.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: Acquire multiple request entry information corresponding to the multiple target APIs from the target library; According to the target test case and the multiple request entry information, perform test processing on the multiple target APIs to obtain multiple test results corresponding to the multiple target APIs; Analyze and process the multiple test results to determine multiple target coverages corresponding to the multiple target APIs; If the multiple target coverage rates are all greater than the coverage rate threshold, generating a test report according to the multiple test results and the multiple target coverage rates; If any target coverage is less than or equal to the coverage threshold, the target test case is regenerated.
7. A test case generation device, characterized in that: include: A receiving module, used for receiving a test case generation request, wherein the test case generation request includes a plurality of target interface identifiers; An acquisition module, used to generate a request according to the test case, determine a plurality of target application programming interfaces API corresponding to the plurality of target interface identifiers, and acquire target interface information of the plurality of target API execution calls through a packet capture technology; A preprocessing module, used for performing data preprocessing on the target interface information to obtain target message data; A generation module is used to generate a target test case according to the target message data.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.