Interface test case generation method and device, terminal equipment and storage medium
By generating and identifying HAR packages automated generation of interface test cases, the problems of low efficiency and high cost of interface test cases in the prior art are solved, and automated writing and maintenance costs are realized.
Patent Information
- Application Number
- CN202411420668.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2024-11-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing interface test case generation process is inefficient and costly, requires a lot of manpower and time to write, and needs to be debugged after writing to maintain parameters and contextual relationships.
By controlling the browser to run the network application of the interface to be tested, a HAR package is generated, and the HAR package is identified to obtain the test case template, the target variable value of the request parameters and the response assertion, and automatically write it to the test case template to generate the interface test case.
It realizes the automated writing of interface test cases, reduces maintenance costs, improves writing efficiency, and avoids the high cost of manual writing.
Smart Images

Figure CN118916298A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of interface testing technology, and in particular to an interface test case generation method, apparatus, terminal equipment and storage medium. Background Art
[0002] One type of testing of web applications is aimed at verifying their functionality and performance and ensuring that the web application works as expected. Testing the interface of the web application is an important part of quality assurance, and its purpose is to ensure the normal operation of communication between the browser and the server.
[0003] Currently, the interfaces of network applications are mainly tested through interface test cases, but interface test cases require a lot of manpower and time to write, and they also need to be debugged after writing to maintain the parameters and context relationships in the interface test cases, which invisibly reduces writing efficiency and increases testing costs.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide an interface test case generation method, device, terminal device and storage medium, aiming to solve the technical problems of low writing efficiency and high cost in the current interface test case generation process.
[0006] To achieve the above purpose, the present application proposes a method for generating an interface test case, which comprises: Control the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; Identify the HAR package, obtain the test case template, the target variable value and / or the target constant value corresponding to the request parameters of each interface to be tested, and obtain the response assertion of each interface to be tested; Write the target variable value and / or target constant value, and the response assertion into the test case template to generate an interface test case.
[0007] In one embodiment, the step of controlling the browser to run the network application corresponding to each interface to be tested to obtain the HAR package includes: Control the browser to run each network application, and record the running process to obtain the communication operation between the interface to be tested and the server when the browser runs the network application; The communication operation is saved in HAR format to obtain a HAR package.
[0008] In one embodiment, the HAR package includes interface data of each interface to be tested, and the steps of identifying the HAR package and obtaining the test case template, the target variable value and / or the target constant value corresponding to the request parameter of each interface to be tested include: By identifying the interface data of each interface to be tested in the HAR package, the interface file content is obtained, wherein the interface file content reflects the information of the interface to be tested; Convert the interface file content into a test case template in a target format; and, by identifying the interface data of each interface to be tested in the HAR package, determine the required variable values and / or required constant values for replacing the request parameters in each interface to be tested; Based on the preset data acquisition operation and the identification order of each interface to be tested, a target variable value that is the same as a required variable value is obtained, and / or a target constant value that is the same as a required constant value is obtained.
[0009] In one embodiment, the preset data acquisition operation includes a first preset data acquisition operation, and based on the preset data acquisition operation and the identification order of each interface to be tested, the step of obtaining a target variable value that is the same as the required variable value, and / or obtaining a target constant value that is the same as the required constant value includes: When the identification order of the current interface to be tested is the first order, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required for the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required for the current interface to be tested is selected.
[0010] In one embodiment, based on the preset data acquisition operation and the identification order of each interface to be tested, the step of obtaining a target variable value that is the same as the required variable value and / or obtaining a target constant value that is the same as the required constant value includes: In the case where the identification order of the current interface to be tested is not the first order, determining whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested; If they are not the same, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required by the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required by the current interface to be tested is selected.
[0011] In one embodiment, the preset data acquisition operation includes a second preset data acquisition operation, after the step of determining whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested, including: If they are the same, based on the second preset data acquisition operation, the data extraction path of the previous interface to be tested is obtained, and the target variable value of the current interface to be tested is obtained through the data extraction path, and / or the target constant value of the current interface to be tested is obtained; The data extraction path is a selection path for obtaining a target variable value and / or a target constant value in a preset database by the previous interface to be tested.
[0012] In one embodiment, the step of obtaining the response assertion of each interface to be tested includes: Determine the response status of each interface to be tested from the HAR packet according to the response code of each interface to be tested; Based on the response status and response code corresponding to each interface to be tested, the response assertion of each interface to be tested is determined.
[0013] In addition, to achieve the above purpose, the present application also proposes an interface test case generation device, the interface test case generation device comprising: The control module is used to control the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; An identification module is used to identify the HAR package, obtain the test case template, the target variable value and / or the target constant value corresponding to the request parameter of each interface to be tested, and obtain the response assertion of each interface to be tested; The generation module is used to write the target variable value and / or target constant value and the response assertion into the test case template to generate an interface test case.
[0014] In addition, to achieve the above-mentioned purpose, the present application also proposes a terminal device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the interface test case generation method described above.
[0015] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the interface test case generation method described above are implemented.
[0016] One or more technical solutions proposed in this application have at least the following technical effects: The invention proposes controlling a browser to run a network application corresponding to each interface to be tested, and obtaining a HAR package, wherein the HAR package includes a resource file, a configuration file, and a manifest file describing the network application. Therefore, based on the HAR package, the interaction context and required parameters between the interface to be tested and the server can be directly determined when the corresponding network application is executed through the corresponding interface to be tested, thereby avoiding the need for additional context and parameter maintenance for subsequently generated interface test cases, and reducing the maintenance cost of the test to a certain extent; identifying the HAR package, obtaining a test case template, target variable values and / or target constant values corresponding to request parameters of each interface to be tested, and obtaining a response assertion of each interface to be tested; writing the target variable values and / or target constant values, and the response assertion into the test case template, and generating an interface test case, thereby avoiding the conventional need for manpower to determine the target variable values and / or target constant values, and the response assertion of the interface to be tested, and performing manual writing of the interface test case based on the determined target variable values and / or target constant values, and the response assertion, and realizing automatic writing of the interface test case through an interface test case generation device, thereby greatly improving writing efficiency and avoiding the high writing cost of manual writing. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] 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.
[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0019] Figure 1 A flowchart of the first embodiment of the method for generating interface test cases of the present application is provided; Figure 2 A flowchart of the second embodiment of the method for generating interface test cases of this application is provided; Figure 3 This is a schematic diagram of the module structure of the interface test case generation device according to an embodiment of the present application; Figure 4 This is a schematic diagram of the device structure of the hardware operating environment involved in the interface test case generation method in the embodiment of the present application.
[0020] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0021] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0022] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0023] The main solution of the embodiment of the present application is: control the browser to run the network application corresponding to each interface to be tested, and obtain a HAR (Harmony Archive, static sharing) package; identify the HAR package, obtain a test case template, target variable values and / or target constant values corresponding to the request parameters of each interface to be tested, and obtain a response assertion of each interface to be tested; write the target variable value and / or target constant value, and the response assertion into the test case template to generate an interface test case.
[0024] In the prior art, the interfaces of network applications are mainly tested through interface test cases, but interface test cases require a lot of manpower and time to write, and they also need to be debugged after writing to maintain the parameters and context relationships in the interface test cases, which invisibly reduces writing efficiency and increases testing costs.
[0025] The present application provides a solution, which enables the control browser to run the network application corresponding to each interface to be tested, and obtains a HAR package, which contains the resource files, configuration files and manifest files describing the network application of the network application. Therefore, based on the HAR package, it is possible to directly determine the interaction context and required parameters between the interface to be tested and the server when the corresponding network application is executed through the corresponding interface to be tested, thereby avoiding the need for additional maintenance of context and parameters for the interface test cases generated subsequently, and reducing the maintenance cost of the test to a certain extent; identifying the HAR package, obtaining the test case template, the configuration files of each interface to be tested, and the configuration files of the network application. The target variable value and / or target constant value corresponding to the request parameter, and the response assertion of each interface to be tested are obtained; the target variable value and / or target constant value, and the response assertion are written into the test case template to generate an interface test case, thereby avoiding the conventional need for manpower to determine the target variable value and / or target constant value of the interface to be tested, and the response assertion, and the manual writing operation of the interface test case is performed based on the determined target variable value and / or target constant value, and the response assertion. The interface test case generation device realizes the automatic writing of the interface test case, which greatly improves the writing efficiency and avoids the high writing cost of manual writing.
[0026] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a terminal device, etc. capable of realizing the above functions. The following takes the terminal device as an example to illustrate this embodiment and the following embodiments.
[0027] Based on this, the present application embodiment provides a method for generating an interface test case, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the interface test case generation method of the present application.
[0028] In this embodiment, the interface test case generation method includes steps S10 to S30: Step S10, controlling the browser to run the network application corresponding to each interface to be tested to obtain a HAR package.
[0029] In the test of the interface that needs to be called when the browser runs a network application, in order to avoid the manual involvement and debugging of the generation process of the interface test cases required for the interface test, the existing interface test case writing efficiency is low and the testing cost is high, this embodiment proposes a method for automatically generating interface test cases. This method can not only avoid the low writing efficiency and high writing labor cost of manually writing interface test cases, but also skip the debugging stage of the written interface test cases, avoid the maintenance cost generated by the debugging of the interface test cases, and further reduce the testing cost for the interface.
[0030] It should be noted that the HAR package in this embodiment is generated by the browser when calling the network applications corresponding to each interface to be tested. Therefore, the HAR package contains the resource files, configuration files and manifest files describing the network applications of the network applications. By identifying the HAR package, the relevant communication process, relevant parameters and communication results involved in the communication between the browser and the server through the interface to be tested can be directly determined, avoiding the low recognition efficiency and high recognition cost caused by manually determining the communication process, relevant parameters and communication results.
[0031] Specifically, after determining the interface to be tested, control the browser to run the network application corresponding to the interface to be tested, obtain the HAR package generated after the network application is run, and prepare to generate interface test cases based on the generated HAR package. At this time, functional testing of the network application can be performed simultaneously to test whether the network application runs correctly according to the design specifications.
[0032] In a feasible implementation, step S10 may include steps S11-S12: Step S11, controlling the browser to run each network application, and recording the running process to obtain the communication operation between the interface to be tested called and the server when the browser runs the network application.
[0033] This embodiment records the running process of the network application by controlling the browser to run the corresponding network application. Specifically, an automated testing tool or a browser plug-in can be used to record the communication operations corresponding to the running process and generate corresponding communication codes, so as to obtain the communication process, related parameters and communication results involved in the browser communicating with the server through the interface to be tested to execute the corresponding network application, so that the context of the interface test case and the parameters required for the interface test case can be directly determined according to the communication process, eliminating the additional maintenance cost generated by debugging the context and parameters. At the same time, based on the communication results, the expected test results required for the interface test case can be directly determined, avoiding the errors caused by manual determination of the expected test results and the test errors caused.
[0034] Step S12, saving the communication operation in HAR format to obtain a HAR package.
[0035] After obtaining the communication code corresponding to the communication operation when the corresponding interface to be tested communicates with the server through the above steps, the communication code is directly saved in HAR format. After outputting it as a HAR package, the HAR package is exported in the browser and stored in the target path. The target path refers to the storage location of the HAR package on the computer or server. Subsequently, the HAR package is directly uploaded to the interface test case generation device through the target path.
[0036] Step S20, identifying the HAR package, obtaining the test case template, the target variable value and / or the target constant value corresponding to the request parameter of each interface to be tested, and obtaining the response assertion of each interface to be tested.
[0037] The interface test case generation device identifies the uploaded HAR package, identifies the communication code corresponding to each interface to be tested in the HAR package, and extracts the corresponding test case template, target variable value and / or target constant value and response assertion according to the communication code.
[0038] Among them, the test case template includes the interface test case number, test conditions, input data, expected results, test steps, etc. Among them, the interface test case number can be numbered according to the identification order of the currently identified interface to be tested; the test conditions are used to describe the functions or characteristics that need to be tested for the interface to be tested; the input data is the target variable value and / or target constant value corresponding to the interface to be tested; the expected result is the response assertion; the test step is the interactive step (also called interactive context) of the browser communicating with the server through the interface to be tested to execute the corresponding network application, which describes how the browser interacts with the server to implement the network application. The specific identification process is described as follows: In a feasible implementation, step S20 may include steps S21 to S24: Step S21: obtaining the interface file content by identifying the interface data of each interface to be tested in the HAR package, wherein the interface file content reflects the information of the interface to be tested.
[0039] Step S22, converting the interface file content into a test case template in a target format.
[0040] By identifying the interface data of each interface to be tested in the HAR package, the interface data that can reflect each interface to be tested is obtained, and then the interface file content is obtained. According to the interface file content, the interface information to be tested of each interface to be tested is specifically included, and information is classified according to the interface information to be tested, and a test case template as shown in Table 1 is constructed according to the classification result.
[0041] Table 1
[0042] Among them, the interface name can be the identification order of the interface to be tested; the interface address is the address used to identify the network interface in the computer network; the request method is the method used by the client to send a request to the server when performing network communication; the request header is the metadata used to describe an HTTP request in the HTTP protocol, and contains a part of the request information sent by the browser to the server through the interface to be tested; and the request parameters are used to carry additional information to tell the server some metadata and parameters about the request; the expected result is the code information corresponding to the successful execution of the corresponding network application by communicating with the server through the interface to be tested.
[0043] By converting the test case template, the information corresponding to the interface to be tested is directly written into the test case template, which can speed up the generation of interface test cases.
[0044] It should be noted that the target format is determined based on the actual conversion process, and can be converted into YAML format, JSON (JavaScript Object Notation) format, or PYTEST format, etc.
[0045] Step S23, determining the required variable value and / or required constant value for replacing the request parameter in each interface to be tested by identifying the interface data of each interface to be tested in the HAR packet.
[0046] The interface test case generation device in this embodiment will automatically identify the incoming HAR packet after receiving the incoming HAR packet, identify the accepted data in each interface to be tested in the HAR packet, that is, the parameters of the relevant request header, identify the variables and / or constants of the queryString parameter of the GET request in the request header parameters, and the variables and / or constants of the postData parameter of the POST request, and determine the identified variables and / or constants as the required variable values and / or required constant values, so as to determine that in the process of testing based on the interface to be tested, the browser can communicate with the server and run the corresponding application. That is, determining the required variable values and required constant values is used to enable the browser to effectively communicate with the server based on the interface to be tested, and adapt to the application scenario of running the corresponding application.
[0047] Step S24, based on the preset data acquisition operation and the identification order of each interface to be tested, obtaining a target variable value that is the same as the required variable value, and / or obtaining a target constant value that is the same as the required constant value.
[0048] It should be noted that this embodiment will select different preset data acquisition operations according to the identification order corresponding to each interface to be tested, so as to speed up the acquisition of target variable values and / or target constant values. Please refer to the specific content of the second embodiment for details, which will not be repeated here.
[0049] In a feasible implementation, step S20 may include steps S25-S26: Step S25, determining the response status of each interface to be tested from the HAR packet according to the response code of each interface to be tested.
[0050] Step S26: Determine the response assertion of each interface to be tested based on the response status and response code respectively corresponding to each interface to be tested.
[0051] Because the HAR package contains a manifest file that describes the network application, that is, the process and results of the browser running the corresponding network application by interacting with the server through the corresponding interface to be tested, the running result can be extracted, and the running result can represent the response result when the interface to be tested communicates with the server, and the response result is determined based on the response code, that is, after obtaining the response code corresponding to each interface to be tested in the HAR package, the communication result between the interface to be tested and the server described by the response code is used to determine the response status of the server to the browser when the browser communicates and interacts with the server through the interface to be tested.
[0052] Therefore, based on the acquired response status and response code of each interface to be tested, the response assertion of each interface to be tested can be determined.
[0053] Among them, response assertion is a verification mechanism, which is used to check whether the verification result of the interface to be tested meets the expected requirements when it enters the verification stage. Therefore, according to the response status and response code corresponding to each interface to be tested, it can be determined that when the interface to be tested is verified later, it can be quickly determined whether it meets the expected requirements according to the corresponding response assertion.
[0054] Step S30, writing the target variable value and / or target constant value, and the response assertion into the test case template to generate an interface test case.
[0055] After obtaining the target variable values and / or target constant values, and response assertions corresponding to each interface to be tested through the above steps, write them into the corresponding areas according to the test case templates corresponding to each interface to be tested, that is, write the target variable values and / or target constant values into the request parameter values in Table 1, and write the response assertions into the expected results, so as to realize fast and convenient generation of interface test cases, avoiding the problems of low writing efficiency and high writing cost existing in manual writing of test cases.
[0056] Among them, the request method and request header are inherent to the interface to be tested.
[0057] In this embodiment, the browser is controlled to run the network application corresponding to each interface to be tested, and a HAR package is obtained. The HAR package includes resource files, configuration files, and a manifest file describing the network application. Therefore, based on the HAR package, the interaction context and required parameters between the interface to be tested and the server can be directly determined when the corresponding network application is executed through the corresponding interface to be tested, thereby avoiding the need for additional context and parameter maintenance for the interface test cases generated subsequently, thereby reducing the maintenance cost of the test to a certain extent; the HAR package is identified to obtain the test case template, the request parameters of each interface to be tested, and the test case template. The target variable value and / or target constant value corresponding to the number, and the response assertion of each interface to be tested are obtained; the target variable value and / or target constant value, and the response assertion are written into the test case template to generate an interface test case, thereby avoiding the conventional need for manpower to determine the target variable value and / or target constant value of the interface to be tested, and the response assertion, and the manual writing operation of the interface test case is performed based on the determined target variable value and / or target constant value, and the response assertion. The interface test case generation device realizes the automatic writing of the interface test case, which greatly improves the writing efficiency and avoids the high writing cost of manual writing.
[0058] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 In step S24, the interface test case generation method further includes steps A10 to A40: Step A10, when the identification order of the current interface to be tested is the first order, based on the first preset data acquisition operation, select the target variable value that is the same as the variable value required for the current interface to be tested from the preset database, and / or select the target constant value that is the same as the constant value required for the current interface to be tested.
[0059] During the identification process of the interface to be tested, when it is identified that the current interface to be tested for which the corresponding interface test case needs to be generated has the first order in the identification process, then the operation of obtaining the target variable value and / or target constant value of the current interface to be tested is determined to be the first preset data acquisition operation.
[0060] It should be noted that the first preset data acquisition operation is to search and select from the preset database a target variable value that is the same as the variable value required by the current interface to be tested, and / or to search and select a target constant value that is the same as the constant value required by the current interface to be tested.
[0061] Among them, the preset database stores preset variable values and preset constant values required for various interfaces. In the process of obtaining the target variable value and the target constant value, after directly searching and selecting the preset variable value and / or preset constant value that are the same as the required variable value and / or the required constant value in the preset database, the selected preset variable value and / or preset constant value is determined as the target variable value and / or the target constant value, thereby avoiding the problems of low writing efficiency and writing errors existing in manually writing variable values and constant values.
[0062] Step A20, when the identification order of the current interface to be tested is not the first order, determine whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested.
[0063] If during the identification process of the interface to be tested, it is identified that the current interface to be tested for which the corresponding interface test case needs to be generated is not identified in the first order during the identification process, it means that an interface has been identified before the current interface to be tested. At this time, in order to speed up the recognition efficiency of the current interface to be tested and to speed up the acquisition of target variable values and / or target constant values, after determining that the identification order of the current interface to be tested is not the first order, it will be further determined whether the required variable values and / or required constant values of the current interface to be tested are the same as the target variable values and / or target constant values of the previous interface to be tested.
[0064] Step A30, if not the same, based on the first preset data acquisition operation, select the target variable value that is the same as the variable value required by the current interface to be tested from the preset database, and / or select the target constant value that is the same as the constant value required by the current interface to be tested.
[0065] If it is determined that the required variable value and / or required constant value of the current interface to be tested is not the same as the target variable value and / or target constant value of the previous interface to be tested, it means that the target variable value and / or target constant value cannot be selected directly through the extraction path of the previous interface to be tested. At this time, based on the first preset data acquisition operation, the preset database is searched for and selected to obtain the target variable value that is the same as the required variable value of the current interface to be tested, and / or the target constant value that is the same as the required constant value of the current interface to be tested is searched and selected.
[0066] Step A40, if the same, then based on the second preset data acquisition operation, obtain the data extraction path of the previous interface to be tested, obtain the target variable value of the current interface to be tested through the data extraction path, and / or obtain the target constant value of the current interface to be tested, wherein the data extraction path is the selection path for the previous interface to be tested to obtain the target variable value and / or target constant value in the preset database.
[0067] If it is determined that the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested, it means that the target variable value and / or target constant value of the current interface to be tested can be directly obtained through the data extraction path of the previous interface to be tested, avoiding the search time required to search in the preset database, and speeding up the selection efficiency of the target variable value and / or target constant value.
[0068] In this embodiment, based on the identification order of each interface to be tested, a preset data acquisition operation for obtaining the target variable value and / or target constant value corresponding to each interface to be tested is determined, thereby reducing the search time required to search and select the target variable value and / or target constant value in the preset database to a certain extent, thereby speeding up the selection efficiency of the target variable value and target constant value.
[0069] This application also provides an interface test case generation device, please refer to Figure 3 , the interface test case generating device comprises: The control module 10 is used to control the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; The identification module 20 is used to identify the HAR package, obtain the test case template, the target variable value and / or the target constant value corresponding to the request parameter of each interface to be tested, and obtain the response assertion of each interface to be tested; The generating module 30 is used to write the target variable value and / or target constant value and the response assertion into the test case template to generate an interface test case.
[0070] Furthermore, the control module 10 is also used for: Control the browser to run each network application, and record the running process to obtain the communication operation between the interface to be tested and the server when the browser runs the network application; The communication operation is saved in HAR format to obtain a HAR package.
[0071] Furthermore, the identification module 20 is also used for: By identifying the interface data of each interface to be tested in the HAR package, the interface file content is obtained, wherein the interface file content reflects the information of the interface to be tested; Convert the interface file content into a test case template in a target format; and, by identifying the interface data of each interface to be tested in the HAR package, determine the required variable values and / or required constant values for replacing the request parameters in each interface to be tested; Based on the preset data acquisition operation and the identification order of each interface to be tested, a target variable value that is the same as a required variable value is obtained, and / or a target constant value that is the same as a required constant value is obtained.
[0072] Furthermore, the identification module 20 is also used for: When the identification order of the current interface to be tested is the first order, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required for the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required for the current interface to be tested is selected.
[0073] Furthermore, the identification module 20 is also used for: In the case where the identification order of the current interface to be tested is not the first order, determining whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested; If they are not the same, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required by the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required by the current interface to be tested is selected.
[0074] Furthermore, the identification module 20 is also used for: If they are the same, based on the second preset data acquisition operation, the data extraction path of the previous interface to be tested is obtained, and the target variable value of the current interface to be tested is obtained through the data extraction path, and / or the target constant value of the current interface to be tested is obtained; The data extraction path is a selection path for obtaining a target variable value and / or a target constant value in a preset database by the previous interface to be tested.
[0075] Furthermore, the identification module 20 is also used for: Determine the response status of each interface to be tested from the HAR packet according to the response code of each interface to be tested; Based on the response status and response code corresponding to each interface to be tested, the response assertion of each interface to be tested is determined.
[0076] The interface test case generation device provided by the present application adopts the interface test case generation method in the above embodiment, which can solve the technical problems of low writing efficiency and high cost in the current interface test case generation process. Compared with the prior art, the beneficial effects of the interface test case generation device provided by the present application are the same as the beneficial effects of the interface test case generation method provided by the above embodiment, and the other technical features in the interface test case generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0077] The present application provides a terminal device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the interface test case generation method in the above-mentioned embodiment one.
[0078] Reference below Figure 4 , which shows a schematic diagram of the structure of a terminal device suitable for implementing an embodiment of the present application. The terminal device in the embodiment of the present application may include but is not limited to mobile terminals such as laptops, PADs (Portable Application Description: tablet computers), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The terminal device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0079] like Figure 4 As shown, the terminal device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the terminal device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the terminal device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a terminal device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0080] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0081] The terminal device provided by the present application adopts the interface test case generation method in the above embodiment, which can solve the technical problems of low writing efficiency and high cost in the current interface test case generation process. Compared with the prior art, the beneficial effects of the terminal device provided by the present application are the same as the beneficial effects of the interface test case generation method provided by the above embodiment, and the other technical features in the terminal device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0082] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0083] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0084] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the interface test case generation method in the above-mentioned embodiment.
[0085] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0086] The computer-readable storage medium may be included in the terminal device; or may exist independently without being installed in the terminal device.
[0087] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by a terminal device, the terminal device: controls the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; identifies the HAR package, obtains a test case template, target variable values and / or target constant values corresponding to the request parameters of each interface to be tested, and obtains a response assertion of each interface to be tested; writes the target variable values and / or target constant values, and the response assertion into the test case template to generate an interface test case.
[0088] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0089] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0090] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0091] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned interface test case generation method, and can solve the technical problems of low writing efficiency and high cost in the current interface test case generation process. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the interface test case generation method provided by the above-mentioned embodiment, and will not be repeated here.
[0092] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for generating an interface test case, characterized in that: The interface test case generation method comprises: Control the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; Identify the HAR packet, obtain a test case template, target variable values and / or target constant values corresponding to request parameters of each interface to be tested, and obtain a response assertion of each interface to be tested; The target variable value and / or the target constant value, and the response assertion are written into the test case template to generate an interface test case.
2. The interface test case generation method according to claim 1, characterized in that: The step of controlling the browser to run the network application corresponding to each interface to be tested to obtain the HAR package includes: Controlling the browser to run each of the network applications, and recording the running process to obtain the communication operation between the interface to be tested called and the server when the browser runs the network application; The communication operation is saved in a HAR format to obtain the HAR package.
3. The interface test case generation method according to claim 1, characterized in that: The HAR package includes interface data of each interface to be tested, and the steps of identifying the HAR package and obtaining a test case template, a target variable value and / or a target constant value corresponding to a request parameter of each interface to be tested include: Obtaining interface file content by identifying interface data of each interface to be tested in the HAR package, wherein the interface file content reflects information of the interface to be tested; Converting the interface file content into a test case template in a target format; and Determine required variable values and / or required constant values for replacing request parameters in each of the interfaces to be tested by identifying interface data of each of the interfaces to be tested in the HAR packet; Based on the preset data acquisition operation and the identification order of each of the interfaces to be tested, a target variable value that is the same as the required variable value is obtained, and / or a target constant value that is the same as the required constant value is obtained.
4. The interface test case generation method according to claim 3, characterized in that: The preset data acquisition operation includes a first preset data acquisition operation, and the step of obtaining a target variable value that is the same as the required variable value and / or obtaining a target constant value that is the same as the required constant value based on the preset data acquisition operation and the identification order of each of the interfaces to be tested includes: When the identification order of the current interface to be tested is the first order, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required for the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required for the current interface to be tested is selected.
5. The interface test case generation method according to claim 4, characterized in that: The step of obtaining a target variable value that is the same as the required variable value and / or obtaining a target constant value that is the same as the required constant value based on the preset data acquisition operation and the identification order of each of the interfaces to be tested comprises: In the case where the identification order of the current interface to be tested is not the first order, determining whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested; If they are not the same, based on the first preset data acquisition operation, a target variable value that is the same as the variable value required by the current interface to be tested is selected from the preset database, and / or a target constant value that is the same as the constant value required by the current interface to be tested is selected.
6. The interface test case generation method according to claim 5, characterized in that: The preset data acquisition operation includes a second preset data acquisition operation, after the step of determining whether the required variable value and / or required constant value of the current interface to be tested is the same as the target variable value and / or target constant value of the previous interface to be tested, including: If they are the same, based on the second preset data acquisition operation, obtain the data extraction path of the previous interface to be tested, obtain the target variable value of the current interface to be tested through the data extraction path, and / or obtain the target constant value of the current interface to be tested; The data extraction path is a selection path for the previous interface to be tested to obtain a target variable value and / or a target constant value in the preset database.
7. The interface test case generation method according to claim 1, characterized in that: The step of obtaining the response assertion of each interface to be tested comprises: Determining the response status of each of the interfaces to be tested from the HAR packet according to the response code of each of the interfaces to be tested; Based on the response status and response code respectively corresponding to each of the interfaces to be tested, the response assertion of each of the interfaces to be tested is determined.
8. An interface test case generation device, characterized in that: The interface test case generating device comprises: A control module is used to control the browser to run the network application corresponding to each interface to be tested to obtain a HAR package; An identification module, used to identify the HAR packet, obtain a test case template, a target variable value and / or a target constant value corresponding to the request parameters of each interface to be tested, and obtain a response assertion of each interface to be tested; A generation module is used to write the target variable value and / or the target constant value, and the response assertion into the test case template to generate an interface test case.
9. A terminal device, characterized in that: The terminal device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the interface test case generation method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the interface test case generation method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
HTTP interface automatic test method and device, equipment and storage medium
CN113505068A
Interface testing method and device
CN113515436A
Method and system for analyzing and automatically generating interface test case based on HAR file format
CN118445210A
Test suite generation from metadata
US20210240600A1
