Interface case generation method and device, computer equipment, medium and product
By automatically generating interface use cases and determining interface parameter values based on parameter constraint rules, the problem of inefficient writing interface use cases is solved, and efficient and accurate interface testing is achieved.
Patent Information
- Application Number
- CN202311766678.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-20
- Publication Date
- 2025-06-27
AI Technical Summary
In large-scale software development projects, relying on manual writing of interface use cases leads to inefficient generation and easy to miss special scenarios, affecting the testing effect of interface use cases.
By responding to interface use cases, obtaining target interface information, and determining interface parameter values based on preset parameter constraint rules, normal, exception and boundary interface use cases are generated.
It realizes automatic generation of interface use cases, improves generation efficiency, ensures the testing accuracy of interface use cases, and covers all possible scenarios.
Smart Images

Figure CN120216347A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of interface testing technology, and particularly to a method, apparatus, computer device, medium, and product for generating interface test cases. Background Art
[0002] With the continuous development of Internet technology, more and more application programs begin to provide service interfaces to the Internet and other systems. However, in large-scale software development projects, interface accidents or interface attacks by hackers often occur, resulting in serious impacts or even paralysis of the entire system function.
[0003] In this case, interface testing emerges as the times require, which is used to test the stability and correctness of interfaces and avoid potential problems during actual user use. Currently, it is usually dependent on manual writing of interface test cases. However, since this method is time-consuming and laborious, it is easy to reduce the generation efficiency of interface test cases. Summary of the Invention
[0004] Based on this, in view of the above technical problems, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for generating interface test cases that can improve the generation efficiency of interface test cases.
[0005] In a first aspect, this application provides a method for generating interface test cases. The method includes:
[0006] Responding to an interface test case creation instruction, obtaining target interface information corresponding to the interface test case creation instruction;
[0007] Obtaining a preset parameter constraint rule, and determining an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0008] Generating a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value.
[0009] In one embodiment, the target interface information includes multiple request parameters, the interface parameter values include normal parameter values corresponding to the multiple request parameters respectively, and the target interface test cases include normal interface test cases, abnormal interface test cases, and boundary interface test cases;
[0010] The generating a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value includes:
[0011] Combining the multiple normal parameter values to generate a normal interface test case corresponding to the interface test case creation instruction;
[0012] Based on the normal interface test case, traversing the parameter constraint rule to obtain the abnormal interface test case and the boundary interface test case.
[0013] In one embodiment, traversing the parameter constraint rules based on the normal interface use cases to obtain the abnormal interface use cases and the boundary interface use cases includes:
[0014] Obtain each request parameter in the normal interface use cases;
[0015] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each request parameter and boundary parameter values corresponding to each request parameter;
[0016] Combine each abnormal parameter value with the normal parameter values corresponding to other request parameters to generate the abnormal interface use cases, and combine each boundary parameter value with the normal parameter values corresponding to other request parameters to generate the boundary interface use cases.
[0017] In one embodiment, traversing the parameter constraint rules to generate abnormal parameter values corresponding to each request parameter and boundary parameter values corresponding to each request parameter includes:
[0018] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each request parameter; the abnormal parameter values do not satisfy the parameter constraint rules;
[0019] Determine boundary value conditions from the parameter constraint rules, and generate boundary parameter values corresponding to each request parameter based on the boundary value conditions.
[0020] In one embodiment, determining the interface parameter values corresponding to the target interface information based on the parameter constraint rules includes:
[0021] Obtain multiple request parameters in the target interface information;
[0022] Extract the constraint conditions corresponding to the multiple request parameters from the parameter constraint rules;
[0023] Generate interface parameter values corresponding to the multiple request parameters based on the constraint conditions.
[0024] In one embodiment, generating the interface parameter values corresponding to each of the multiple request parameters based on the constraint conditions further includes:
[0025] Determine the value information corresponding to the multiple request parameters based on the constraint conditions; the value information includes a value type and a value range;
[0026] Generate the interface parameter values corresponding to each of the multiple request parameters according to the value type and the value range.
[0027] In one embodiment, generating the target interface use case corresponding to the interface use case creation instruction according to the interface parameter value further includes:
[0028] Generating a plurality of candidate interface use cases corresponding to the interface use case creation instruction according to the interface parameter value;
[0029] Inserting a preset assertion template into each of the plurality of candidate interface use cases to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
[0030] In a second aspect, the present application further provides a device for generating interface use cases. The device includes:
[0031] An interface information acquisition module, configured to acquire target interface information corresponding to the interface use case creation instruction in response to the interface use case creation instruction;
[0032] A parameter value generation module, configured to acquire a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0033] An interface use case generation module, configured to generate a target interface use case corresponding to the interface use case creation instruction according to the interface parameter value.
[0034] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0035] In response to the interface use case creation instruction, acquiring target interface information corresponding to the interface use case creation instruction;
[0036] Acquiring a preset parameter constraint rule, and determining an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0037] Generating a target interface use case corresponding to the interface use case creation instruction according to the interface parameter value.
[0038] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0039] In response to the interface use case creation instruction, acquiring target interface information corresponding to the interface use case creation instruction;
[0040] Acquiring a preset parameter constraint rule, and determining an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0041] Generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value.
[0042] In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program which, when executed by a processor, implements the following steps:
[0043] In response to an interface test case creation instruction, obtain target interface information corresponding to the interface test case creation instruction;
[0044] Obtain a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0045] Generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value.
[0046] For the above method, device, computer device, computer-readable storage medium, and computer program product for generating an interface test case, first, in response to an interface test case creation instruction, obtain target interface information corresponding to the interface test case creation instruction, then obtain a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule. The interface parameter value generated under the parameter constraint rule has a certain degree of accuracy, avoiding the influence of incorrect values of the interface parameter value on the test effect of the interface test case during the test process, and ensuring the test accuracy of the target interface test case. Finally, generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value. Through the above method, automatic generation of interface test cases is achieved, eliminating the need for manual writing and effectively improving the generation efficiency of interface test cases. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 It is an application scenario diagram of the method for generating an interface test case in an embodiment;
[0048] Figure 2 It is a flowchart of the method for generating an interface test case in an embodiment;
[0049] Figure 3 It is a flowchart of the process for generating an interface test case in an embodiment;
[0050] Figure 4 It is a flowchart of the process for parameter combination in an embodiment;
[0051] Figure 5 It is a flowchart of the process for extracting constraint conditions corresponding to request parameters in an embodiment;
[0052] Figure 6 It is a flowchart of the process for writing an assertion template in an embodiment;
[0053] Figure 7 Schematic diagram of the application architecture of the interface use case generation method in an embodiment;
[0054] Figure 8 Schematic diagram of the process of importing target interface information in an embodiment;
[0055] Figure 9 Schematic diagram of the generation process of normal interface use cases and abnormal interface use cases in an embodiment;
[0056] Figure 10 Schematic diagram of the generation process of boundary interface use cases in an embodiment;
[0057] Figure 11 Block diagram of the structure of the interface use case generation device in an embodiment;
[0058] Figure 12 Internal structure diagram of a computer device in an embodiment. Detailed implementation manners
[0059] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0060] With the continuous development of Internet technology, more and more application programs begin to provide service interfaces to the Internet and other systems. However, in large-scale software development projects, interface accidents or interface attacks by hackers often occur, resulting in serious impacts or even paralysis of the entire system function.
[0061] In this case, interface testing emerges as the times require, which is used to test the stability and correctness of the interface and avoid possible problems in the actual user usage process. Currently, it is usually dependent on manual writing of interface use cases. However, in a complex system, there may be a large number of interfaces, and it takes a lot of time and manpower to manually write the use cases for each interface, which easily leads to a decrease in the generation efficiency of interface use cases. Moreover, it is easy to be negligent when manually writing use cases, such as omitting some special scenarios, so that the interface use cases cannot cover all scenarios during operation, posing a certain risk.
[0062] The method for generating interface test cases provided by the embodiments of the present disclosure can be applied to the application environment shown in FIG. 1. Among them, the server 102 is connected to the terminal 104. The server 102 receives an interface test case creation instruction from the terminal 104 and obtains the target interface information corresponding to the interface test case creation instruction. And obtain the preset parameter constraint rules, determine the interface parameter values corresponding to the target interface information based on the parameter constraint rules, and thus generate the target interface test case corresponding to the interface test case creation instruction according to the interface parameter values. Among them, the server 102 can be implemented by an independent server or a server cluster composed of multiple servers. The terminal 104 can be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, and Internet of Things devices.
[0063] In one embodiment, as Figure 2 shown, a method for generating interface test cases is provided. Taking the server 102 in Figure 1 as an example, the method includes the following steps:
[0064] Step S202, in response to the interface test case creation instruction, obtain the target interface information corresponding to the interface test case creation instruction.
[0065] Among them, the interface test case creation instruction can be an instruction for indicating the creation of a target interface test case. The target interface information can refer to information including multiple interface parameters. The interface parameters include, but are not limited to, interface encoding, interface address, request type, query parameters, path parameters, request headers, and other parameters.
[0066] In one embodiment, the target interface information can be uploaded to the server in the form of a JSON (JavaScript Object Notation, lightweight data interchange format) file, or can be uploaded to the server in the form of an Excel (Microsoft Office Excel, table) file, or the interface information can be batch imported through the swagger address of the server where the interface is located. Swagger is an open-source tool built based on the OpenAPI (Open Application Programming Interface) specification. The interface information can also be manually created. The specific method of entering interface information is not limited here and can be adjusted according to the actual situation.
[0067] Specifically, the user can pre-enter the target interface information through the terminal. In this way, when the server senses the interface use case creation instruction for the target interface information triggered by the user through the terminal, it can directly obtain the target interface information, extract multiple request parameters from the target interface information, and generate interface parameter values corresponding to each of the multiple request parameters, thereby generating a target interface use case corresponding to the interface use case creation instruction. Among them, the request parameter is a parameter in the interface parameter, and the request parameter can have corresponding constraint conditions, and the interface parameter value corresponding to the request parameter can be generated based on the constraint conditions.
[0068] Step S204, obtain the preset parameter constraint rules, and determine the interface parameter values corresponding to the target interface information based on the parameter constraint rules.
[0069] Among them, the parameter constraint rule can refer to the value constraint rule of the request parameter in the target interface information. The parameter constraint rule can include constraint conditions corresponding to each of the multiple request parameters. These constraint conditions specify the value range and value type of the multiple request parameters, so as to obtain the interface parameter values corresponding to the multiple request parameters. The interface parameter value refers to the value generated by the multiple request parameters based on the parameter constraint rules.
[0070] In an embodiment, the interface parameter values can include normal parameter values, abnormal parameter values, and boundary parameter values. The normal parameter value can refer to the value that satisfies the parameter constraint rule, the abnormal parameter value can refer to the value that does not satisfy the parameter constraint rule, and the boundary parameter value can refer to the value that satisfies the boundary value condition in the parameter constraint rule.
[0071] For example, for the request parameter A, its corresponding constraint condition is that the value range is [0, 100]. Then the values within (0, 100) belong to the normal parameter values corresponding to the request parameter A, the values greater than 100 or less than 0 belong to the abnormal parameter values corresponding to the request parameter A, and 0 and 100 belong to the boundary parameter values corresponding to the request parameter A.
[0072] Specifically, the parameter constraint rules created in advance are stored in the server. After obtaining the target interface information, the constraint conditions corresponding to each request parameter can be extracted from the parameter constraint rules to generate corresponding normal parameter values, abnormal parameter values, and boundary parameter values for each request parameter. Thus, based on the normal parameter values, abnormal parameter values, and boundary parameter values corresponding to each request parameter, a target interface use case corresponding to the interface use case creation instruction is generated.
[0073] In an embodiment, the parameter constraint rules can be created following the JsonSchema specification. JsonSchema is a specification for describing JSON data structures, providing a structured way to define the expected structure, type, format, constraint conditions, etc. of JSON data.
[0074] Step S206: Generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value.
[0075] Among them, the target interface test case can refer to an interface test case for interface testing, which can include normal interface test cases, abnormal interface test cases, and boundary interface test cases.
[0076] Specifically, after the server obtains the normal parameter value, abnormal parameter value, and boundary parameter value according to the parameter constraint rule, it can combine all the normal parameter values to obtain a normal interface test case, combine the normal parameter value and the abnormal parameter value to obtain an abnormal interface test case, and combine the normal parameter value and the boundary parameter value to obtain a boundary interface test case.
[0077] In this embodiment, first, in response to the interface test case creation instruction, obtain the target interface information corresponding to the interface test case creation instruction, then obtain the preset parameter constraint rule, determine the interface parameter value corresponding to the target interface information based on the parameter constraint rule. The interface parameter value generated under the parameter constraint rule has a certain accuracy, which avoids affecting the test effect of the interface test case due to incorrect value selection of the interface parameter value during the test process, and ensures the test accuracy of the target interface test case. Finally, generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value. Through the above method, automatic generation of interface test cases is realized, without manual writing, effectively improving the generation efficiency of interface test cases.
[0078] In one embodiment, as Figure 3 shown, generating a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value includes:
[0079] Step S302: Combine multiple normal parameter values to generate a normal interface test case corresponding to the interface test case creation instruction.
[0080] Among them, the normal interface test case can refer to a test case containing all normal parameter values, which can be used to verify the processing ability of the interface under normal circumstances.
[0081] Specifically, after the server obtains the normal parameter values corresponding to each request parameter, it can combine each normal parameter value to obtain a normal interface test case. The normal parameter values can be randomly combined or combined according to the generation time of each normal parameter value. The specific combination order is not limited here and can be adjusted according to the actual situation.
[0082] Step S304: Based on the normal interface test case, traverse the parameter constraint rule to obtain the abnormal interface test case and the boundary interface test case.
[0083] Among them, the abnormal interface use cases can refer to the use cases that contain abnormal parameter values and normal parameter values, which can be used to verify the processing ability of the interface in abnormal situations. For example, when an abnormal value is input, it can be verified whether the interface can handle the abnormal situation and return an appropriate error message. The boundary interface use cases can refer to the use cases that contain boundary parameter values and normal parameter values, which can be used to verify the processing ability of the interface in boundary situations, that is, extreme situations. This is because errors and exceptions often occur when the interface processes boundary values. By generating interface use cases from the three aspects of normal, abnormal, and boundary, the running situations of the interface can be covered in a wide range, so that the running situations and processing abilities of the interface in any situation can be obtained, thereby improving the accuracy of interface testing.
[0084] Specifically, after the server generates the normal interface use cases, it traverses the constraint conditions corresponding to each request parameter, thereby generating the abnormal parameter values and boundary parameter values corresponding to each request parameter, and then combines the abnormal parameter values and normal parameter values to generate abnormal interface use cases, and combines the boundary parameter values and normal parameter values to generate boundary interface use cases.
[0085] In this embodiment, by generating normal interface use cases, abnormal interface use cases, and boundary interface use cases, the interfaces in normal situations, abnormal situations, and boundary situations can be tested, so as to obtain the running situations and processing abilities of the interface in the above situations, thereby improving the accuracy of interface testing.
[0086] In one embodiment, as Figure 4 shown, based on the normal interface use cases, traversing the parameter constraint rules to obtain the abnormal interface use cases and boundary interface use cases, including:
[0087] Step S402, obtain each request parameter in the normal interface use case.
[0088] Specifically, after the server generates the normal interface use cases, it can obtain each request parameter in the normal interface use case again to generate the abnormal parameter values and boundary parameter values corresponding to each request parameter.
[0089] Step S404, traverse the parameter constraint rules to generate the abnormal parameter values corresponding to each request parameter respectively, and the boundary parameter values corresponding to each request parameter respectively.
[0090] Specifically, the server traverses the constraint conditions corresponding to each request parameter, generates abnormal parameter values that do not meet the constraint conditions, and generates boundary parameter values based on the constraint conditions.
[0091] In one embodiment, the server can extract the boundary value-taking conditions from the constraint conditions and generate the corresponding boundary parameter values based on the boundary value-taking conditions, where the boundary value-taking conditions refer to the value-taking conditions for the boundary parameter values.
[0092] For example, assume that the normal interface case 1 includes the normal parameter values b, c, and d. Among them, the normal parameter value b corresponds to the request parameter B, the normal parameter value c corresponds to the request parameter C, and the normal parameter value d corresponds to the request parameter D. After the server generates this normal interface case 1, it traverses the constraint conditions corresponding to the request parameters B, C, and D respectively, and these constraint conditions are extracted from the parameter constraint rules. Based on the constraint conditions corresponding to the request parameters B, C, and D respectively, the abnormal parameter values corresponding to the request parameters B, C, and D are generated in reverse. That is, the value that does not meet the constraint condition corresponding to the request parameter B is the abnormal parameter value corresponding to the request parameter B, the value that does not meet the constraint condition corresponding to the request parameter C is the abnormal parameter value corresponding to the request parameter C, and the value that does not meet the constraint condition corresponding to the request parameter D is the abnormal parameter value corresponding to the request parameter D. In this way, the abnormal parameter values corresponding to the request parameters B, C, and D can be obtained. As for the boundary parameter values corresponding to the request parameters B, C, and D respectively, taking the request parameter B as an example, assume that the constraint condition corresponding to the request parameter B is that the value ranges from [1, 10]. Then the boundary value condition of the request parameter B is also the limit values of this range, that is, 1 and 10. Therefore, 1 or 10 is used as the boundary parameter value of the request parameter B. Similarly, the boundary parameter values corresponding to the request parameters C and D can be obtained.
[0093] Step S406: Combine each abnormal parameter value with the normal parameter values corresponding to other request parameters to generate abnormal interface cases, and combine each boundary parameter value with the normal parameter values corresponding to other request parameters to generate boundary interface cases.
[0094] Among them, other request parameters may refer to other request parameters except the request parameters corresponding to each abnormal parameter value or each boundary parameter value.
[0095] Specifically, the server combines each abnormal parameter value with the normal parameter values corresponding to other request parameters to obtain abnormal interface cases. There may be only one abnormal parameter value in an abnormal interface case, and the rest are normal parameter values. And combines each boundary parameter value with the normal parameter values corresponding to other request parameters to obtain boundary interface cases. Similarly, there may be only one boundary parameter value in a boundary interface case, and the rest are normal parameter values.
[0096] For example, taking the normal interface use case 1 as an example again, after obtaining the abnormal parameter values and boundary parameter values corresponding to the request parameters B, C, and D respectively, the abnormal parameter value corresponding to the request parameter B can be combined with the normal parameter values corresponding to the request parameters C and D respectively to obtain an abnormal interface use case. The abnormal parameter value corresponding to the request parameter C is combined with the normal parameter values corresponding to the request parameters B and D respectively to obtain another abnormal interface use case, and so on, until the abnormal parameter values of each request parameter are combined with the other normal parameter values. Similarly, for the boundary interface use case, the boundary parameter value corresponding to the request parameter B can be combined with the normal parameter values corresponding to the request parameters C and D respectively to obtain a boundary interface use case, and so on, until the boundary parameter values of each request parameter are combined with the other normal parameter values.
[0097] In this embodiment, considering that in actual applications, most often an abnormal situation occurs in a certain request parameter while the other parameters are normal, the abnormal interface use cases are generated by combining the abnormal parameter values with the normal parameter values, and the boundary interface use cases are generated by combining the boundary parameter values with the normal parameter values, which is more in line with the actual application scenario and improves the accuracy and reliability of the interface use cases.
[0098] In one embodiment, as Figure 5 shown, determining the interface parameter values corresponding to the target interface information based on the parameter constraint rules includes:
[0099] Step S502, obtaining multiple request parameters in the target interface information.
[0100] Step S504, extracting the constraint conditions corresponding to the multiple request parameters from the parameter constraint rules.
[0101] Specifically, after the server obtains the multiple request parameters in the target interface information, it can extract the constraint conditions corresponding to each request parameter from the parameter constraint rules according to the attribute information of each request parameter.
[0102] In one embodiment, the attribute information may include the parameter name, that is, the corresponding constraint conditions can be extracted according to the parameter name of each request parameter. The attribute information may also include the parameter description, and the parameter description may refer to the introduction information about the request parameter. For example, for the request parameter url, its parameter description may be the interface address, and the corresponding constraint conditions can also be extracted according to the parameter description. It can also be adjusted according to the actual situation.
[0103] Step S506, generating the interface parameter values corresponding to the multiple request parameters based on the constraint conditions.
[0104] Specifically, after extracting the constraint conditions corresponding to each request parameter, the interface parameter values corresponding to each request parameter can be generated according to the constraint conditions.
[0105] In one embodiment, the value information corresponding to multiple request parameters can be determined based on the constraint conditions; the value information includes a value type and a value range; according to the value type and the value range, the interface parameter values corresponding to multiple request parameters are generated respectively.
[0106] Among them, the value type can refer to the type of the interface parameter value corresponding to the request parameter, and the value range can refer to the value interval of the interface parameter value corresponding to the request parameter.
[0107] Specifically, the value type and the value range when each request parameter takes a value can be extracted from the constraint conditions corresponding to each request parameter, so that the interface parameter values corresponding to each request parameter are generated according to the value type and the value range.
[0108] In this embodiment, by extracting the constraint conditions corresponding to each request parameter from the parameter constraint rules, the value type and the value range are determined based on the constraint conditions, and then the interface parameter values corresponding to each request parameter are generated according to the value type and the value range. The accuracy of generating the interface parameter values is improved, thereby improving the accuracy of the finally generated target interface use case.
[0109] In one embodiment, as Figure 6 shown, generating the target interface use case corresponding to the interface use case creation instruction according to the interface parameter value further includes:
[0110] Step S602, generating a plurality of candidate interface use cases corresponding to the interface use case creation instruction according to the interface parameter value.
[0111] Step S604, inserting a preset assertion template into each of the plurality of candidate interface use cases to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
[0112] Among them, the candidate interface use case can refer to the interface use case that has not yet added the assertion template. It should be noted that in practical applications, it is also necessary to verify the execution situation of each interface use case to determine whether the interface use case meets the expectations. Therefore, a preset assertion template can be added to the interface use case, that is, the assertion template and the interface parameter value jointly constitute the final target interface use case.
[0113] An assertion is a programming tool that can be used to determine whether a certain condition is true in a program. It is applicable to interface testing. An assertion contains a judgment condition. During the execution of an interface test case, when the execution reaches the position where the assertion is located, the assertion can determine whether the current running result is true. If it is true, it means that the running result meets the expectation, and then the execution continues. If it is false, it means that the running result does not meet the expectation, and an exception prompt can be output. An assertion template can refer to templatized assertion description text, and different types of assertion templates can be written according to different interface test scenarios.
[0114] Specifically, the server generates multiple candidate interface test cases corresponding to the interface test case creation instruction according to the interface parameter values. Here, the candidate interface test cases can refer to normal interface test cases without written assertion templates, abnormal interface test cases without written assertion templates, and boundary interface test cases without written assertion templates. Then, the assertion template is written into the candidate interface test cases to obtain the complete template interface test cases.
[0115] In one embodiment, the assertion template can be written at any position in the candidate interface test case.
[0116] In this embodiment, by inserting the assertion template into the candidate interface test case, the final target interface test case is obtained, achieving the purpose of automatically verifying the execution result of the target interface test case, avoiding the cumbersome process of manual verification, reducing the influence of human factors on the execution result at the same time, and improving the accuracy of the interface test case.
[0117] In a specific embodiment, referring to Figure 7The architecture diagram shown includes defining parameter constraint rules. Before generating interface test cases, parameter constraint rules can be defined first. These parameter constraint rules follow the JsonSchema specification. For example, for the string type, default values are supported, and the length range is from the minimum length to the maximum length. For the format type, such as date-time (date - time), date (date), time (time), url (Uniform Resource Locator), email (email), IP (Internet Protocol), regular expression constraints and enumerated values are supported. For the integer type, default values are supported, and the numerical range is between the minimum value and the maximum value, with enumerated values. For the number type, default values are also supported, and the numerical range is between the minimum value and the maximum value, with enumerated values. For the boolean type, default values are supported, and true or false can be selected from a dropdown. For the array type, whether the elements are unique and the number of elements (from the minimum number to the maximum number) can be selected. The architecture diagram also includes generating normal parameter values, obtaining normal parameter values, generating abnormal parameter values, generating boundary parameter values, obtaining normal interface test cases, abnormal interface test cases, and boundary interface test cases. Then, an assertion template is generated through a test case general assertor, and the assertion template is combined with the normal interface test cases, error interface test cases, and boundary interface test cases respectively to obtain complete normal interface test cases, complete abnormal interface test cases, and complete boundary interface test cases. Finally, the complete normal interface test cases, complete abnormal interface test cases, and complete boundary interface test cases are sent to the test case lake for storage.
[0118] In one embodiment, the parameter constraint rules can refer to Table 1. It should be noted that the data types shown in Table 1 do not include those mentioned above.
[0119] Table 1
[0120]
[0121] The above architecture can be deployed on the TPP (Interface Automation Testing Platform). When the TPP platform receives an interface test case creation instruction, it first obtains the target interface information corresponding to the interface test case creation instruction. The target interface information can refer to Table 2.
[0122] Table 2
[0123]
[0124] In one embodiment, referring to Figure 8 , the target interface information can be uploaded to the TTP platform in the form of a JSON file, or in the form of an Excel file, or through a swagger address.
[0125] After the TTP platform obtains the target interface information, the TTP platform can call the pre-created parameter constraint rules, extract the constraint conditions corresponding to each request parameter from the parameter constraint rules, and then generate the normal parameter values that meet the constraint conditions, the abnormal parameter values that do not meet the constraint conditions, and the boundary parameter values that meet the boundary value conditions for each request parameter. Then, the normal parameter values corresponding to each request parameter are combined to obtain normal interface test cases, the abnormal parameter values corresponding to each request parameter are combined with the normal parameter values corresponding to other request parameters to obtain abnormal interface test cases, as Figure 9 shown, and the boundary parameter values corresponding to each request parameter are combined with the normal parameter values corresponding to other request parameters to obtain boundary interface test cases, as Figure 10 shown. Finally, assertion templates are added to each interface test case to obtain the final target interface test cases. The structure table of the finally generated target interface test cases is shown in Table 3.
[0126] Table 3
[0127]
[0128] In this embodiment, when the TPP platform receives an interface test case creation instruction, it obtains the target interface information corresponding to the interface test case creation instruction, then obtains the preset parameter constraint rules, determines the interface parameter values corresponding to the target interface information based on the parameter constraint rules. The interface parameter values generated under the parameter constraint rules have a certain degree of accuracy, which avoids affecting the test effect of the interface test cases due to incorrect values of the interface parameter values during the test process, and ensures the test accuracy of the target interface test cases. Finally, according to the interface parameter values, the target interface test cases corresponding to the interface test case creation instruction are generated. Through the above method, the automatic generation of interface test cases is realized, without manual writing, effectively improving the generation efficiency of interface test cases.
[0129] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps does not have a strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be executed alternately or alternately with at least a part of other steps or steps in other steps.
[0130] Based on the same inventive concept, an embodiment of the present application further provides an interface use case generation device for implementing the above-mentioned interface use case generation method. The implementation solution provided by this device to solve problems is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more embodiments of the interface use case generation device provided below can refer to the limitations on the interface use case generation method in the foregoing, and will not be elaborated herein.
[0131] In one embodiment, as Figure 11 shown, an interface use case generation device is provided, including: an interface information acquisition module 1102, a parameter value generation module 1104, and an interface use case generation module 1106, where:
[0132] The interface information acquisition module 1102 is configured to obtain target interface information corresponding to the interface use case creation instruction in response to the interface use case creation instruction;
[0133] The parameter value generation module 1104 is configured to obtain a preset parameter constraint rule and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0134] The interface use case generation module 1106 is configured to generate a target interface use case corresponding to the interface use case creation instruction according to the interface parameter value.
[0135] In one of the embodiments, the interface use case generation module 1106 further includes:
[0136] The first use case generation unit is configured to combine multiple normal parameter values to generate a normal interface use case corresponding to the interface use case creation instruction;
[0137] The second use case generation unit is configured to traverse the parameter constraint rule based on the normal interface use case to obtain the abnormal interface use case and the boundary interface use case.
[0138] In one of the embodiments, the second use case generation unit further includes:
[0139] The parameter acquisition subunit is configured to acquire each request parameter in the normal interface use case;
[0140] The parameter value generation subunit is configured to traverse the parameter constraint rule to generate abnormal parameter values corresponding to each request parameter and boundary parameter values corresponding to each request parameter;
[0141] A combinatorial subunit for combining each of the abnormal parameter values with the normal parameter values corresponding to other request parameters respectively to generate the abnormal interface use cases, and combining each of the boundary parameter values with the normal parameter values corresponding to other request parameters respectively to generate the boundary interface use cases.
[0142] In one embodiment, the parameter value generation subunit is further configured to:
[0143] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each of the request parameters; the abnormal parameter values do not satisfy the parameter constraint rules;
[0144] Determine the boundary value conditions from the parameter constraint rules, and generate boundary parameter values corresponding to each of the request parameters based on the boundary value conditions.
[0145] In one embodiment, the parameter value generation module 1104 is further configured to:
[0146] A parameter acquisition module for acquiring a plurality of request parameters in the target interface information;
[0147] A condition extraction module for extracting constraint conditions corresponding to the plurality of request parameters respectively from the parameter constraint rules;
[0148] A parameter value generation sub-module for generating interface parameter values corresponding to the plurality of request parameters respectively based on the constraint conditions.
[0149] In one embodiment, the parameter value generation sub-module is further configured to:
[0150] Determine value information corresponding to the plurality of request parameters respectively based on the constraint conditions; the value information includes a value type and a value range;
[0151] Generate interface parameter values corresponding to each of the plurality of request parameters according to the value type and the value range.
[0152] In one embodiment, the interface use case generation module 1106 is further configured to:
[0153] Generate a plurality of candidate interface use cases corresponding to the interface use case creation instruction according to the interface parameter values;
[0154] Insert a preset assertion template into the plurality of candidate interface use cases respectively to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
[0155] Each module in the above interface case generation device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or stored in a memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0156] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 12 shown. The computer device includes a processor, a memory, and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store item recommendation data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a method for generating an interface case.
[0157] Those skilled in the art can understand that Figure 12 the structure shown in
[0158] is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have a different component layout.
[0159] In response to an interface case creation instruction, obtain the target interface information corresponding to the interface case creation instruction;
[0160] Obtain a preset parameter constraint rule, and determine the interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0161] According to the interface parameter value, generate the target interface case corresponding to the interface case creation instruction.
[0162] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0163] Combine multiple normal parameter values to generate a normal interface case corresponding to the interface case creation instruction;
[0164] Traverse the parameter constraint rules based on the normal interface use cases to obtain the abnormal interface use cases and the boundary interface use cases.
[0165] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0166] Obtain each of the request parameters in the normal interface use cases;
[0167] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each of the request parameters, and boundary parameter values corresponding to each of the request parameters;
[0168] Combine each of the abnormal parameter values with the normal parameter values corresponding to other request parameters to generate the abnormal interface use cases, and combine each of the boundary parameter values with the normal parameter values corresponding to other request parameters to generate the boundary interface use cases.
[0169] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0170] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each of the request parameters; the abnormal parameter values do not satisfy the parameter constraint rules;
[0171] Determine the boundary value conditions from the parameter constraint rules, and generate boundary parameter values corresponding to each of the request parameters based on the boundary value conditions.
[0172] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0173] Obtain multiple request parameters in the target interface information;
[0174] Extract the constraint conditions corresponding to the multiple request parameters from the parameter constraint rules;
[0175] Generate interface parameter values corresponding to the multiple request parameters based on the constraint conditions.
[0176] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0177] Determine the value information corresponding to the multiple request parameters based on the constraint conditions; the value information includes a value type and a value range;
[0178] Generate interface parameter values corresponding to each of the multiple request parameters according to the value type and the value range.
[0179] In one embodiment, when the processor executes the computer program, the following steps are further implemented:
[0180] Generate a plurality of candidate interface test cases corresponding to the interface test case creation instruction according to the interface parameter value;
[0181] Insert a preset assertion template into each of the plurality of candidate interface test cases to obtain the target interface test case; the assertion template is used to verify the execution result of the target interface test case.
[0182] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0183] In response to an interface test case creation instruction, obtain target interface information corresponding to the interface test case creation instruction;
[0184] Obtain a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0185] Generate a target interface test case corresponding to the interface test case creation instruction according to the interface parameter value.
[0186] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0187] Combine the multiple normal parameter values to generate a normal interface test case corresponding to the interface test case creation instruction;
[0188] Traverse the parameter constraint rule based on the normal interface test case to obtain the abnormal interface test case and the boundary interface test case.
[0189] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0190] Obtain each request parameter in the normal interface test case;
[0191] Traverse the parameter constraint rule to generate abnormal parameter values corresponding to each request parameter respectively, and boundary parameter values corresponding to each request parameter respectively;
[0192] Combine each abnormal parameter value with the normal parameter values corresponding to other request parameters respectively to generate the abnormal interface test case, and combine each boundary parameter value with the normal parameter values corresponding to other request parameters respectively to generate the boundary interface test case.
[0193] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0194] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each of the request parameters; the abnormal parameter values do not satisfy the parameter constraint rules;
[0195] Determine boundary value conditions from the parameter constraint rules, and generate boundary parameter values corresponding to each of the request parameters based on the boundary value conditions.
[0196] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0197] Obtain multiple request parameters in the target interface information;
[0198] Extract constraint conditions corresponding to the multiple request parameters from the parameter constraint rules;
[0199] Generate interface parameter values corresponding to the multiple request parameters based on the constraint conditions.
[0200] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0201] Determine value information corresponding to the multiple request parameters based on the constraint conditions; the value information includes a value type and a value range;
[0202] Generate interface parameter values corresponding to each of the multiple request parameters according to the value type and the value range.
[0203] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0204] Generate multiple candidate interface use cases corresponding to the interface use case creation instruction according to the interface parameter values;
[0205] Insert a preset assertion template into each of the multiple candidate interface use cases to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
[0206] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0207] In response to an interface use case creation instruction, obtain target interface information corresponding to the interface use case creation instruction;
[0208] Obtain a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule;
[0209] Generate a target interface use case corresponding to the interface use case creation instruction according to the interface parameter values.
[0210] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0211] Combine the multiple normal parameter values to generate a normal interface use case corresponding to the interface use case creation instruction;
[0212] Based on the normal interface use case, traverse the parameter constraint rules to obtain the abnormal interface use case and the boundary interface use case.
[0213] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0214] Obtain each request parameter in the normal interface use case;
[0215] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each request parameter respectively, and boundary parameter values corresponding to each request parameter respectively;
[0216] Combine each abnormal parameter value with the normal parameter values corresponding to other request parameters respectively to generate the abnormal interface use case, and combine each boundary parameter value with the normal parameter values corresponding to other request parameters respectively to generate the boundary interface use case.
[0217] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0218] Traverse the parameter constraint rules to generate abnormal parameter values corresponding to each request parameter respectively; the abnormal parameter values do not satisfy the parameter constraint rules;
[0219] Determine the boundary value conditions from the parameter constraint rules, and based on the boundary value conditions, generate boundary parameter values corresponding to each request parameter respectively.
[0220] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0221] Obtain multiple request parameters in the target interface information;
[0222] Extract the constraint conditions corresponding to the multiple request parameters respectively from the parameter constraint rules;
[0223] Based on the constraint conditions, generate interface parameter values corresponding to the multiple request parameters respectively.
[0224] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0225] Based on the above constraints, determine the value information corresponding to each of the multiple request parameters; the value information includes a value type and a value range;
[0226] According to the value type and the value range, generate interface parameter values corresponding to each of the multiple request parameters.
[0227] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0228] According to the interface parameter values, generate multiple candidate interface use cases corresponding to the interface use case creation instruction;
[0229] Insert a preset assertion template into each of the multiple candidate interface use cases to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
[0230] 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 for analysis, stored data, displayed data, etc.) involved in this application are all information and data that have been authorized by the user or fully authorized by all parties.
[0231] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0232] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0233] The above-described embodiments only represent several implementation manners of the present application. Their descriptions are relatively specific and detailed, but they should not be construed as limiting the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A method for generating interface test cases, characterized in that The method includes: In response to an interface use case creation instruction, obtaining target interface information corresponding to the interface use case creation instruction; Obtaining a preset parameter constraint rule, and determining interface parameter values corresponding to the target interface information based on the parameter constraint rule; Generating a target interface use case corresponding to the interface use case creation instruction according to the interface parameter values.
2. The method according to claim 1, wherein The target interface information includes multiple request parameters, the interface parameter values include normal parameter values respectively corresponding to the multiple request parameters, and the target interface use case includes a normal interface use case, an abnormal interface use case, and a boundary interface use case; The generating a target interface use case corresponding to the interface use case creation instruction according to the interface parameter values includes: Combining the multiple normal parameter values to generate a normal interface use case corresponding to the interface use case creation instruction; Based on the normal interface use case, traversing the parameter constraint rule to obtain the abnormal interface use case and the boundary interface use case.
3. The method according to claim 2, characterized in that The traversing the parameter constraint rule based on the normal interface use case to obtain the abnormal interface use case and the boundary interface use case includes: Obtaining each of the request parameters in the normal interface use case; Traversing the parameter constraint rule to generate abnormal parameter values respectively corresponding to the request parameters and boundary parameter values respectively corresponding to the request parameters; Combining each abnormal parameter value with the normal parameter values corresponding to other request parameters respectively to generate the abnormal interface use case, and combining each boundary parameter value with the normal parameter values corresponding to other request parameters respectively to generate the boundary interface use case.
4. The method according to claim 3, characterized in that, The traversing the parameter constraint rule to generate abnormal parameter values respectively corresponding to the request parameters and boundary parameter values respectively corresponding to the request parameters includes: Traversing the parameter constraint rule to generate abnormal parameter values respectively corresponding to the request parameters; the abnormal parameter values do not satisfy the parameter constraint rule; Determining boundary value conditions from the parameter constraint rule, and generating boundary parameter values respectively corresponding to the request parameters based on the boundary value conditions.
5. The method according to claim 1, characterized in that The determining interface parameter values corresponding to the target interface information based on the parameter constraint rule includes: Obtaining multiple request parameters in the target interface information; Extracting constraint conditions respectively corresponding to the multiple request parameters from the parameter constraint rule; Generating interface parameter values respectively corresponding to the multiple request parameters based on the constraint conditions.
6. The method according to claim 5, wherein The generating interface parameter values respectively corresponding to the multiple request parameters based on the constraint conditions further includes: Determining value information respectively corresponding to the multiple request parameters based on the constraint conditions; the value information includes a value type and a value range; Generating interface parameter values respectively corresponding to the multiple request parameters according to the value type and the value range.
7. The method according to claim 1, wherein The generating a target interface use case corresponding to the interface use case creation instruction according to the interface parameter values further includes: Generating multiple candidate interface use cases corresponding to the interface use case creation instruction according to the interface parameter values; Insert a preset assertion template into each of the multiple candidate interface use cases to obtain the target interface use case; the assertion template is used to verify the execution result of the target interface use case.
8. An apparatus for generating interface test cases, characterized in that, The device includes: An interface information acquisition module, configured to acquire target interface information corresponding to the interface use case creation instruction in response to the interface use case creation instruction; A parameter value generation module, configured to acquire a preset parameter constraint rule, and determine an interface parameter value corresponding to the target interface information based on the parameter constraint rule; An interface use case generation module, configured to generate a target interface use case corresponding to the interface use case creation instruction according to the interface parameter value.
9. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.