Interface test case generation method, device, equipment and storage medium

文档序号:7446 发布日期:2021-09-17 浏览:36次 中文

1. A test case generation method of an interface is characterized by comprising the following steps:

receiving an interface description document, and setting a corresponding number for an interface in the interface description document;

reading necessary description information of an interface in the interface description document, and generating the name of a test case based on an interface number, the name of the interface in the necessary description information, and type information of the test case or attribute information of an input parameter;

generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information;

and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

2. The method of claim 1, wherein the test case is a forward test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

generating first test data based on the value range and the value type of the input parameter;

and if the input parameters are the necessary input parameters, assigning the first test data to the input parameters according to the input format to generate the input parameter values of the test case.

3. The method of claim 1, wherein the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

if the first input parameter of the interface is a mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case;

determining second test data based on the corresponding value range and the value type aiming at second input parameters except the first input parameters;

and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case.

4. The method according to claim 3, wherein generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter comprises:

if the first input parameter is a necessary filling input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary filling input parameters, generating the name of the test case based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter;

correspondingly, the encoding type in the output parameter corresponding to the first input parameter in the expected result is that the parameter is null.

5. The method of claim 1, wherein the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises an input parameter name and a format of a corresponding input parameter;

determining third test data which exceed the value range of a third input parameter and accord with the value type of the third input parameter;

if the third input parameter is a mandatory input parameter, assigning the third input parameter to the third test data according to the input format to generate a third input parameter value of the test case;

determining fourth test data based on the corresponding value range and the value type aiming at fourth input parameters except the third input parameters;

and if the fourth input parameter is a mandatory input parameter, assigning the fourth input parameter to the fourth test data according to the input format to generate a fourth input parameter value of the test case.

6. The method according to claim 5, wherein generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter comprises:

if the third input parameter is a necessary input parameter and the sequence number of the third input parameter is less than or equal to the total number of the necessary input parameters, generating the name of the test case based on the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter;

correspondingly, the encoding type in the output parameter corresponding to the third input parameter in the expected result is invalid.

7. The method of claim 2, wherein generating the name of the test case based on the interface number, the interface name in the necessary description information, and the type information of the test case comprises:

and generating the name of the test case based on the interface number, the interface name and the forward type of the test case.

8. An interface test case generation device, comprising:

the receiving/setting module is used for receiving the interface description document and setting a corresponding number for the interface in the interface description document;

the first generation module is used for reading necessary description information of the interface in the interface description document and generating the name of the test case based on the interface number, the interface name in the necessary description information and the type information of the test case or the attribute information of the input parameter;

the second generation module is used for generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary filling input parameter, the value range of the input parameter and the value type in the necessary description information;

and the third generation module is used for generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

9. An electronic device, comprising:

one or more processors;

a storage device for storing one or more programs,

when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.

10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 7.

Background

The interface test is a test for testing interfaces among system components, and is an important component of the test, and the test is mainly used for checking the correctness of interface parameter transmission, the correctness of interface function realization, the correctness of output results and the integrity and the reasonability of fault-tolerant processing of various abnormal conditions.

At present, in the process of realizing interface testing, a large number of test cases need to be compiled manually, a large amount of time is consumed, and the requirement for testing a rapid and efficient software project cannot be met.

Disclosure of Invention

The embodiment of the invention provides a method, a device, equipment and a storage medium for generating interface test cases, which can be used for quickly generating batch interface test cases, saving time and labor cost, improving test efficiency, avoiding misoperation in the process of manually compiling the test cases and ensuring the accuracy of the test cases.

In a first aspect, an embodiment of the present invention provides a method for generating a test case of an interface, where the method includes:

receiving an interface description document, and setting a corresponding number for an interface in the interface description document;

reading necessary description information of an interface in the interface description document, and generating the name of a test case based on an interface number, the name of the interface in the necessary description information, and type information of the test case or attribute information of an input parameter;

generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information;

and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

Optionally, the test case is a forward test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

generating first test data based on the value range and the value type of the input parameter;

and if the input parameters are the necessary input parameters, assigning the first test data to the input parameters according to the input format to generate the input parameter values of the test case.

Optionally, the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

if the first input parameter of the interface is a mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case;

determining second test data based on the corresponding value range and the value type aiming at second input parameters except the first input parameters;

and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

if the first input parameter is a necessary filling input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary filling input parameters, generating the name of the test case based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter;

correspondingly, the encoding type in the output parameter corresponding to the first input parameter in the expected result is that the parameter is null.

Optionally, the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises an input parameter name and a format of a corresponding input parameter;

determining third test data which exceed the value range of a third input parameter and accord with the value type of the third input parameter;

if the third input parameter is a mandatory input parameter, assigning the third input parameter to the third test data according to the input format to generate a third input parameter value of the test case;

determining fourth test data based on the corresponding value range and the value type aiming at fourth input parameters except the third input parameters;

and if the fourth input parameter is a mandatory input parameter, assigning the fourth input parameter to the fourth test data according to the input format to generate a fourth input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

if the third input parameter is a necessary input parameter and the sequence number of the third input parameter is less than or equal to the total number of the necessary input parameters, generating the name of the test case based on the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter;

correspondingly, the encoding type in the output parameter corresponding to the third input parameter in the expected result is invalid.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the type information of the test case includes:

and generating the name of the test case based on the interface number, the interface name and the forward type of the test case.

In a second aspect, an embodiment of the present invention provides an interface test case generation apparatus, including:

the receiving/setting module is used for receiving the interface description document and setting a corresponding number for the interface in the interface description document;

the first generation module is used for reading necessary description information of the interface in the interface description document and generating the name of the test case based on the interface number, the interface name in the necessary description information and the type information of the test case or the attribute information of the input parameter;

the second generation module is used for generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary filling input parameter, the value range of the input parameter and the value type in the necessary description information;

and the third generation module is used for generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

In a third aspect, an embodiment of the present invention provides an electronic device, including:

one or more processors;

a storage device for storing one or more programs,

when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the methods provided by the embodiments of the present invention.

In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program is used to implement a method provided by an embodiment of the present invention when executed by a processor.

According to the technical scheme provided by the embodiment of the invention, the corresponding number is set for the interface in the interface description document, the necessary description information of the interface in the interface description document is read, and the name of the test case is generated based on the interface number, the interface name in the necessary description information, and the type information or the attribute information of the input parameter of the test case, so that the information of the test case can be conveniently known and distinguished; the method comprises the steps of reading necessary description information in an interface description document, generating input parameter values of test cases according to request type content types, input parameter names and input parameters in the necessary description information, determining whether the input parameters are necessary to be filled, the value range of the input parameters and the numerical value types, and generating expected results of the test cases according to output parameters and response time in the necessary description information, so that batch interface test cases can be generated quickly, time and labor cost are saved, test efficiency is improved, misoperation in the process of manually compiling the test cases is avoided, accuracy of the test cases is guaranteed, comprehensive test cases can be covered, and therefore comprehensive testing of interfaces is conducted. Under the condition that the test case is a forward test case, the name of the test case is generated through the interface number, the interface name and the forward type of the test case, so that a tester can conveniently and quickly know the information of the test case, the test case can be distinguished conveniently, and the input format of the input parameters is determined through the request type and the content type in the interface description file; the method comprises the steps of generating first test data through the value range and the value type of input parameters, if the input parameters are input parameters which must be filled, assigning the input parameters according to an input format to the first test data to generate input parameter values of test cases, and generating expected results of the test cases based on response time and output parameters in interface description documents. Under the condition that the test case is a reverse test case, the name of the test case is generated based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter, so that the information of the test case can be conveniently known, the verification attribute of the test case can be conveniently distinguished, the efficiency of interface test is improved, and the input format of the input parameter is determined through the request type and the content type; if the first input parameter of the interface is the mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case; determining second test data according to the corresponding value range and the value type aiming at second input parameters except the first input parameters; and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case, and generating an input parameter value of the reverse test case, so that the non-empty verification is performed on the input parameter of the mandatory input parameter of the interface, and the comprehensive test is performed on the interface. And under the condition that the test case is a reverse test case, obtaining a third input parameter value of the test case by determining third test data which exceeds the value range and accords with the value type and assigning the test data to a third input parameter, namely obtaining the third input parameter value of the test case by assigning the third input parameter as an invalid parameter value, and verifying the validity of the input parameter which belongs to the necessary input parameter by using the coding type in the output parameter corresponding to the third input parameter in the expected result as the invalid parameter to generate the test case, so that the interface can be comprehensively tested.

Drawings

Fig. 1a is a flowchart of a test case generation method for an interface according to an embodiment of the present invention;

fig. 1b is a flowchart of a test case generation method for an interface according to an embodiment of the present invention;

fig. 2 is a flowchart of a test case generation method for an interface according to an embodiment of the present invention;

fig. 3 is a flowchart of a test case generation method for an interface according to an embodiment of the present invention;

fig. 4 is a flowchart of a test case generation method for an interface according to an embodiment of the present invention;

fig. 5 is a block diagram of a test case generating device of an interface according to an embodiment of the present invention;

fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.

Detailed Description

The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.

In the related art, a test case is a case of a set of test inputs, execution conditions, and expected results written for a particular target to verify whether a particular software requirement is met. The interface may be an application program interface, and may be a predefined interface, such as a function interface, a HyperText Transfer Protocol (HTTP) interface, and the like.

In the related art, the interface test is a test for testing interfaces between components of a system, and is mainly used for testing interfaces between the test system and other external systems and testing interfaces between sub-modules in the system. The interface test mainly checks the correctness of interface parameter transmission, the correctness of interface function realization, the correctness of output results, and the integrity and the reasonableness of fault-tolerant processing of various abnormal conditions. Errors (bugs) in computer programs can be discovered in advance through interface testing, which has the advantage of being cost-effective as the interface testing can be automated and is continuously integrated.

In the interface test process, a test case of the interface needs to be compiled, and the test case is executed to complete the test of the interface. The design of the test case of the interface has similarities with the design of the unit test case, and basic test methods such as a boundary value method and an equivalence method need to be adopted. The starting point of the test case for designing the interface is to verify the consistency of the function and performance index realized by the interface and the interface description document.

At present, the test case compiling of the interface is mainly realized in a manual mode, and the implementation process is as follows: firstly, an interface description document is needed to be referred to, the name of input parameters, the numerical type, the value range, whether the input parameters need to be filled and the like of each interface are determined, wherein the combination of the input parameters needs to follow the design methods of test cases such as an equivalence class method, a boundary value method and the like, all typical input parameter combinations are covered by the minimum number of the test cases, each test case covers different test points, and each test case can not be replaced. Secondly, according to the interface description document, all possible returned output results of each interface are determined, corresponding expected results are added into the response assertions of the test cases respectively, and whether the interface functions are correct or not is judged by judging the consistency of the actual output results of the interfaces and the expected results of the interface test cases. And finally, adding an expected result of the response time into the response assertion of the test case, and judging whether the performance of the interface meets the requirement by judging whether the actual response time of the interface reaches the expected result.

When the input parameters and the output results of a certain interface are too many, in order to ensure the coverage rate of the test, various tests need to be performed on each input parameter, and corresponding input parameters need to be constructed for the possibility of outputting the results, so as to generate a test case for verifying whether the actual output results of the interface meet the expected results. The more complex the interface is, the more test points are, the more the number of test cases written for the interface is, in a conventional software test project, the more the test cases of one interface may be, the time consumed by a mode of manually writing the test cases cannot meet the test requirements of a fast and efficient software project, and in the process of manually writing the test cases, problems that the input parameters are wrongly written or the test cases cannot pass due to other operations may exist, and the time is wasted when the problems are checked.

In order to solve the above problem, an embodiment of the present invention provides a method for generating a test case of an interface, and fig. 1a is a flowchart of the method for generating a test case of an interface, where the method may be executed by a device for generating a test case of an interface, the device may be implemented by software and/or hardware, the device may be configured in an electronic device, and the method may be applied in a scenario of interface testing.

As shown in fig. 1a, the technical solution provided by the embodiment of the present invention includes:

s110: receiving an interface description document, and setting a corresponding number for an interface in the interface description document.

In the embodiment of the present invention, the interface description document may be written in advance by a developer according to a function to be tested of the interface, and the interface description document may be a normalized interface description document. The interface description document comprises necessary description information of one or more interfaces, wherein the necessary description information comprises a request type, an interface path, a content-type input parameter name, whether the input parameter is a necessary input parameter, a value range of the input parameter, a value type of the input parameter, response time and an output parameter.

For example, table 1 is an example of an interface description document, and as shown in table 1, the interface description document includes a request type, an interface path, a content-type, an input parameter name, whether the input parameter is a must-fill input parameter, a value range of the input parameter, a value type of the input parameter, a response time, and an output parameter. For example, the interface name is user login, the request type is post, the response time is 3s, and the input parameter names include username, password, age, birthday, and the like.

TABLE 1

In the embodiment of the present invention, optionally, the interface description document is received, the total number of interfaces in the interface description document may be read, and a corresponding number is set for the interface in the interface description document. For example, the interfaces may be numbered in sequence, and the number of the interface may be 01,02 … … N. The serial number is set for the interface, and the serial number can be used for generating the name of the test case.

S120: reading necessary description information of the interface in the interface description document, and generating the name of the test case based on the interface number, the interface name in the necessary description information, and the type information of the test case or the attribute information of the input parameter.

In the embodiment of the present invention, a limitation may be set for reading the necessary description information of the interface in the interface specification document, or the limitation may not be set. Alternatively, in the case where a limitation is set for reading the necessary description information of the interfaces in the interface specification document, for example, in the case where the number of the interfaces is smaller than the total number of the interfaces in the interface specification document, the necessary information of the interfaces in the interface specification document may be read. The method is characterized in that a limiting condition is set for reading the interface description document, so that the necessary description information of the interfaces in the interface description document can be conveniently and sequentially read in a circulating mode, and a plurality of test cases are generated by only one section of code program.

In the embodiment of the present invention, the type information of the test case may include a forward type of the test case and a reverse type of the test case. The attribute information of the input parameter may include attribute information of whether the input parameter is valid, whether the input parameter is a padding parameter, and the like.

In the embodiment of the present invention, the test case may include a forward test case and a reverse test case. The forward test case can be understood as inputting correct input parameters, and whether the interface can return correct output parameters is verified. The reverse test case can be understood as inputting wrong input parameters, and whether the interface feeds back corresponding output parameters is verified. Under the condition that the test case is a forward test case, the name of the test case can be generated based on the interface name, the interface number and the type information of the test case, so that testers can conveniently know and distinguish the information of the test case. Under the condition that the test case is a reverse test case, the name of the test case can be generated based on the interface name, the interface number and the attribute information of the input parameter, so that testers can conveniently know and distinguish the information of the test case, and the interface test is facilitated.

And S130, generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information.

In an embodiment of the present invention, the request types of the interface may include a post request and a get request, a content type (content-type), a Multipurpose Internet Mail Extensions (MIME) for indicating resources in an entity header, and in response, the content-type header may notify the client of the content type of the content actually returned, and in the request, the client may notify the server of the data type actually sent. The input parameter name and whether the input parameter is a fill-necessary input parameter may refer to the examples in table 1. The value range of the input parameter can be understood as the length range of the input parameter, and the numerical type can include a character string type, an integer value type, and the like.

In the embodiment of the present invention, optionally, an input format of the input parameter may be generated based on the request type and the content type, where the input format may include an input parameter name and a format of the input parameter. For example, the format of the input parameters may be { "mandatory input parameter 1": a, "must fill input parameter 2": b, "must fill in parameter 3": c. Optionally, test data may be generated based on "whether the input parameter is a must-fill input parameter, a value range of the input parameter, and a value type", so that the test data is assigned to the corresponding input parameter, and an input parameter value of the test case is generated.

Therefore, the test case can be generated to cover more comprehensively and test the interface more comprehensively by generating the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is necessary to fill the input parameter, the value range of the input parameter and the value type.

S140: and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

In an embodiment of the present invention, the response time may be used to verify the performance of the interface, and the output parameters may include a code type (code), data (data), and a message type (msg). For example, as shown in table 1, codes of the output parameters may include 0, 1001, 1002, etc., which respectively represent normal, empty, invalid, etc., and msg may include tune, false, etc.

In the embodiment of the invention, the expected result of the test case can be generated through the response time and the output parameters of the interface in the interface description document, the test case can be formed through the input parameter values and the expected result, the test case is executed, and the expected result and the actual output result of the test case can be compared, so that the correctness of the test case is verified.

FIG. 1b is a flowchart of a test case generation method for an interface according to an embodiment of the present invention, and as shown in FIG. 1b, the method includes the steps of starting, receiving an interface description document; reading the total number of interfaces in the interface description document, and setting a corresponding number for each interface; judging whether the interface number is less than or equal to the total number of the interfaces, if not, ending the process; if yes, reading necessary description information in the interface description document, and generating a test case of the interface based on the necessary description information and the interface number. The step of generating the test case of the interface based on the necessary description information of the interface includes steps S120 to S140 in the above embodiment. Specific description may be found in the above embodiments.

According to the technical scheme provided by the embodiment of the invention, the corresponding number is set for the interface in the interface description document, the necessary description information of the interface in the interface description document is read, and the name of the test case is generated based on the interface number, the interface name in the necessary description information, and the type information or the attribute information of the input parameter of the test case, so that the information of the test case can be conveniently known and distinguished; the method comprises the steps of reading necessary description information in an interface description document, generating input parameter values of test cases according to request type content types, input parameter names and input parameters in the necessary description information, determining whether the input parameters are necessary to be filled, the value range of the input parameters and the numerical value types, and generating expected results of the test cases according to output parameters and response time in the necessary description information, so that batch interface test cases can be generated quickly, time and labor cost are saved, test efficiency is improved, misoperation in the process of manually compiling the test cases is avoided, accuracy of the test cases is guaranteed, comprehensive test cases can be covered, and therefore comprehensive testing of interfaces is conducted.

Fig. 2 is a flowchart of a method for generating a test case of an interface according to an embodiment of the present invention, where in this embodiment, the test case is a forward test case.

Optionally, the generating of the input parameter value of the test case based on the request type, the content type, the name of the input parameter, whether the input parameter is a mandatory input parameter, the value range of the input parameter, and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

generating first test data based on the value range and the value type of the input parameter;

and if the input parameters are the necessary input parameters, assigning the first test data to the input parameters according to the input format to generate the input parameter values of the test case.

Optionally, the name of the test case is generated based on the interface number, the interface name and the forward type of the test case.

As shown in fig. 2, the technical solution provided by the embodiment of the present invention includes:

s210: receiving an interface description document, and setting a corresponding number for an interface in the interface description document.

S220: reading the necessary description information of the interface in the interface specification document.

In the embodiment of the present invention, reference may be made to the description of the above embodiment for S210-S220.

S230: and generating the name of the test case based on the interface number, the interface name and the forward type of the test case.

In the embodiment of the present invention, the name of the test case includes an interface number, an interface name, and a forward type of the test case, for example, the name of the generated test case may be interface number _ interface name _ forward. The name format for generating the test case is not limited to the above format, and may be other formats.

Therefore, the name of the test case is generated through the interface number, the interface name and the forward type of the test case, so that a tester can conveniently and quickly know the information of the test case, and the test case can be conveniently distinguished.

S240: determining an input format of an input parameter based on the request type and the content type; wherein the input format comprises the input parameter name and the format of the corresponding input parameter.

In the embodiment of the present invention, the input format of the input parameter may be determined by a request type and a content-type, wherein the request type may be a post request and the content-type may be json. Wherein, the input format of the input parameter can be { "must fill input parameter 1": a, "must fill input parameter 2": b, "must fill in parameter 3": c.

S250: and generating first test data based on the value range and the value type of the input parameters.

In the embodiment of the invention, the length range of the input parameter can be determined based on the value range of the input parameter, whether the input parameter is a character string or an integer value can be determined through the value type, and first test data meeting requirements can be generated by calling a random generation function based on the value range and the value type. For example, the numerical type of the input parameter 1 must be int, and the value range [0, 100] is taken, and test data meeting requirements can be generated by calling a random function, and the test data can be used as first test data.

S260: and if the input parameters are the necessary input parameters, assigning the first test data to the input parameters according to the input format to generate the input parameter values of the test case.

In the embodiment of the invention, if the input parameter is the mandatory input parameter, the first test data is assigned to the input parameter according to the input format to obtain the input parameter value of the test case. For example, if the input format is { "must fill input parameter 1": a, "must fill input parameter 2": b, "must fill in parameter 3": c, filling the numerical type of the input parameter 1 to be int, and setting the value range to be [0, 100], generating first test data by calling a random generation function, and assigning the first test data to the input parameter a to obtain the input parameter value of the test case.

S270: and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

In an embodiment of the invention, the expected result includes two parts, including response time and output parameters, respectively. Wherein, the output parameter of the forward test case can be { "code": 0; "msg" means false; "data": ...}. And if the code type of the expected result of the forward test case is 0, the representation is normal.

For other descriptions of S270, reference may be made to the descriptions of the above embodiments.

Therefore, if the test case is a forward test case, determining the input format of the input parameters through the request type and the content type in the interface description file; the method comprises the steps of generating first test data through the value range and the value type of input parameters, if the input parameters are input parameters which must be filled, assigning the input parameters according to an input format to the first test data to generate input parameter values of test cases, and generating expected results of the test cases based on response time and output parameters in interface description documents.

Fig. 3 is a flowchart of a method for generating a test case of an interface according to an embodiment of the present invention, where in this embodiment, the test case is a reverse test case, and the test case may perform non-null verification on input parameters belonging to a must-fill input parameter.

Optionally, the generating of the input parameter value of the test case based on the request type, the content type, the name of the input parameter, whether the input parameter is a mandatory input parameter, the value range of the input parameter, and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

if the first input parameter of the interface is a mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case;

determining second test data based on the corresponding value range and the value type aiming at second input parameters except the first input parameters;

and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

and if the first input parameter is a necessary filling input parameter and the sequence number of the first input parameter is less than the total number of the necessary filling input parameters, generating the name of the test case based on the interface number, the interface name, the first input parameter name and the actual unnecessary information of the first input parameter.

As shown in fig. 3, the technical solution provided by the embodiment of the present invention includes:

s310: receiving an interface description document, and setting a corresponding number for an interface in the interface description document.

S320: reading the necessary description information of the interface in the interface specification document.

In the embodiment of the present invention, reference may be made to the above-mentioned embodiments for the introduction of S310 to S320.

S330: and if the first input parameter is a necessary filling input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary filling input parameters, generating the name of the test case based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter.

In the embodiment of the present invention, the total number of input parameters belonging to the fill-necessary input parameters in the interface description document may be determined, and the sorting order may be set for the input parameters belonging to the fill-necessary input parameters. If the first input parameter is the necessary input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary input parameters, generating the name of the test case; otherwise, the flow ends.

In the embodiment of the present invention, optionally, the name of the test case may be generated based on the interface number, the interface name, the name of the first input parameter belonging to the mandatory input parameter, and the actual optional information of the first input parameter. For example, if the first input parameter is X and is a padding parameter, the name of the generated test case may be the interface number _ interface name _ padding input parameter X _ padding.

Therefore, if the first input parameter is the mandatory input parameter and the sequence number of the first input parameter is less than or equal to the total number of the mandatory input parameters, the name of the test case is generated based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter, so that the information of the test case can be conveniently known, the verification attribute of the test case can be conveniently distinguished, and the efficiency of interface testing is improved.

S340: determining an input format of an input parameter based on the request type and the content type; wherein the input format comprises the input parameter name and the format of the corresponding input parameter.

In the embodiment of the present invention, reference may be made to the corresponding descriptions in the above embodiments for the description of S340.

S350: and if the first input parameter of the interface is the mandatory input parameter, assigning the first input parameter to a null value according to the input format by the first input parameter, and generating a first input parameter value of the test case.

In the embodiment of the invention, if the first input parameter is the mandatory input parameter, the first input parameter can be assigned as a null value according to the input format, and then the first input parameter value of the test case is generated. For example, the input format is { "must fill input parameter 1": a, "must fill input parameter 2": b, "must fill in parameter 3": c., the first input parameter is a fill-necessary input parameter 1, and a corresponding to the fill-necessary input parameter 1 can be assigned as a null value.

S360: and determining second test data based on the corresponding value range and the value type aiming at second input parameters except the first input parameters.

In an embodiment of the present invention, each interface has a plurality of corresponding input parameters. In addition to the first input parameter, the input parameters of the interface are second input parameters, wherein the number of the second input parameters including the parameter may be at least one. The generation of the second test data is the same as the method of the first test data in the above embodiment, and will not be described again.

S370: and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case.

In the embodiment of the present invention, a method for generating the second input parameter value of the test case is the same as the method for generating the input parameter value described in S260 in the foregoing embodiment, and a description thereof will not be repeated.

S380: and generating an expected result of the test case based on the response time and the output parameters in the necessary description information, wherein the encoding type in the output parameters corresponding to the first input parameters in the expected result is null.

In the embodiment of the present invention, since the first input parameter is a mandatory input parameter, but the first input parameter is assigned as a null value, a code in the output parameter corresponding to the first input parameter in the expected result is 1001, and the characterization parameter is null, thereby implementing the correspondence between the input parameter value of the test case and the expected result.

It should be noted that the execution sequence of S350-S370 is not limited to the execution sequence in the above embodiment, and may also be other execution sequences, for example, the two steps of S360 and S370 are executed before S350, or the execution sequence may also be adjusted according to actual situations.

Thus, the input format of the input parameters is determined by the request type and the content type; if the first input parameter of the interface is the mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case; determining second test data according to the corresponding value range and the value type aiming at second input parameters except the first input parameters; and if the second input parameter is the mandatory fill input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case, and generating an input parameter value of the reverse test case, so that the non-empty verification is performed on the input parameter of the mandatory fill input parameter of the interface, and the comprehensive test is performed on the interface.

Fig. 4 is a flowchart of a method for generating a test case of an interface according to an embodiment of the present invention, where in this embodiment, optionally, the test case is a reverse test case, and the test case may perform validity verification on input parameters belonging to a must-fill input parameter.

Optionally, the generating of the input parameter value of the test case based on the request type, the content type, the name of the input parameter, whether the input parameter is a mandatory input parameter, the value range of the input parameter, and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises an input parameter name and a format of a corresponding input parameter;

determining third test data which exceed the value range of a third input parameter and accord with the value type of the third input parameter;

if the third input parameter is a mandatory input parameter, assigning the third input parameter to the third test data according to the input format to generate a third input parameter value of the test case;

determining fourth test data based on the corresponding value range and the value type aiming at fourth input parameters except the third input parameters;

and if the fourth input parameter is a mandatory input parameter, assigning the fourth input parameter to the fourth test data according to the input format to generate a fourth input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

and if the third input parameter is a necessary input parameter and the sequence number of the third input parameter is less than the total number of the necessary input parameters, generating the name of the test case based on the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter.

As shown in fig. 4, the technical solution provided by the embodiment of the present invention includes:

s410: receiving an interface description document, and setting a corresponding number for an interface in the interface description document.

S420: reading the necessary description information of the interface in the interface specification document.

In the present embodiment, reference may be made to the description of the above embodiments for the description of S410-S420.

S430: and if the third input parameter is a necessary input parameter and the sequence number of the third input parameter is less than the total number of the necessary input parameters, generating the name of the test case based on the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter.

In the embodiment of the invention, the total number of the input parameters belonging to the necessary input parameters in the interface description document can be determined, and the sorting sequence number is set for the input parameters belonging to the necessary input parameters. If the first input parameter is the necessary input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary input parameters, generating the name of the test case; otherwise, the flow ends.

In the embodiment of the invention, the name of the test case can be generated based on the interface number, the interface name, the name of the third input parameter belonging to the required input parameter and the invalid attribute information of the third input parameter. For example, the third input parameter may be the input parameter Y, and the name of the generated test case may be the interface number _ interface name _ input parameter Y _ invalid.

Therefore, the name of the test case is generated through the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter, so that the verification attribute of the test case can be conveniently known, the test case can be conveniently distinguished, and the efficiency of interface testing is improved.

S440: determining an input format of an input parameter based on the request type and the content type; the input format comprises an input parameter name and a format of a corresponding input parameter.

In the embodiment of the present invention, reference may be made to the corresponding descriptions in the above embodiments for the description of S440.

S450: and determining third test data which exceed the value range of the third input parameter and conform to the value type of the third input parameter.

In the embodiment of the invention, the random generation function can be called to generate the third test data which exceeds the value range and accords with the value type through the value range and the value type of the third input parameter. For example, if the value range of the third input parameter is [1,100], the value type is int, and the generated third test data may be 120, where 120 is not in the value range of the third input parameter but conforms to the value type. For another example, if the value range of the third input parameter is [5,10], if the value type is str, then the length of the representation character string is [5,10], then a random generation function may be called to generate a character string whose length is not within the range of [5,10], for example, third test data abc may be generated, and the value range of abc exceeds the value range of the third input parameter and conforms to the value type of the third input parameter.

S460: and if the third input parameter is a mandatory input parameter, assigning the third input parameter to the third test data according to the input format to generate a third input parameter value of the test case.

In the embodiment of the invention, the third test data is assigned to the third input parameter to obtain the third input parameter value of the test case, and the third input parameter value is invalid because the third test data exceeds the value range of the third input parameter, so that the validity verification of the input parameters belonging to the necessary input parameters can be carried out by inputting the invalid input parameter values.

S470: and determining fourth test data based on the corresponding value range and the value type aiming at fourth input parameters except the third input parameters.

In an embodiment of the present invention, each interface has a plurality of corresponding input parameters. In addition to the third input parameter, the input parameters of the interface are fourth input parameters, wherein the number of the fourth input parameters including the parameter may be at least one. The generation of the fourth test data is the same as the method of the first test data in the above embodiment, and will not be described again.

S480: and if the fourth input parameter is a mandatory input parameter, assigning the fourth input parameter to the fourth test data according to the input format to generate a fourth input parameter value of the test case.

In the embodiment of the present invention, a method for generating the fourth input parameter value of the test case is the same as the method for generating the input parameter value described in S260 in the foregoing embodiment, and a description thereof will not be repeated.

S490: generating an expected result of the test case based on the response time and the output parameters in the necessary description information; and the encoding type in the output parameter corresponding to the third input parameter in the expected result is invalid.

In the embodiment of the invention, the value range of the third test data is taken out, the third test data is assigned to the third input parameter, the third input parameter value is an invalid parameter value, the code in the output parameter corresponding to the third input parameter in the expected result is 1002, and the characterization parameter is invalid, so that the input parameter value of the test case is corresponding to the expected result, a correct test case is generated, and the interface is correctly tested.

Therefore, the third input parameter value of the test case is obtained by determining the third test data which exceeds the value range and accords with the value type, assigning the test data to the third input parameter, namely, assigning the third input parameter as an invalid parameter value to obtain the third input parameter value of the test case, and the generated test case can carry out validity verification on the input parameter which belongs to the necessary input parameter by taking the coding type in the output parameter corresponding to the third input parameter in the expected result as the parameter invalid, so that the interface can be comprehensively and correctly tested.

Fig. 5 is a block diagram of a structure of a test case generation apparatus for an interface according to an embodiment of the present invention, and as shown in fig. 5, the apparatus includes: a receiving/setting module 510, a first generating module 520, a second generating module 530, and a third generating module 540.

The receiving/setting module 510 is configured to receive an interface description document, and set a corresponding number for an interface in the interface description document;

a first generating module 520, configured to read necessary description information of an interface in the interface specification document, and generate a name of a test case based on an interface number, an interface name in the necessary description information, and type information of the test case or attribute information of an input parameter;

a second generating module 530, configured to generate an input parameter value of the test case based on the request type, the content type, the name of the input parameter, whether the input parameter is a mandatory input parameter, a value range of the input parameter, and a value type in the necessary description information;

and a third generating module 540, configured to generate an expected result of the test case based on the response time and the output parameter in the necessary description information.

Optionally, the test case is a forward test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

generating first test data based on the value range and the value type of the input parameter;

and if the input parameters are the necessary input parameters, assigning the first test data to the input parameters according to the input format to generate the input parameter values of the test case.

Optionally, the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises the input parameter name and a format of a corresponding input parameter;

if the first input parameter of the interface is a mandatory input parameter, assigning the first input parameter as a null value according to the input format, and generating a first input parameter value of the test case;

determining second test data based on the corresponding value range and the value type aiming at second input parameters except the first input parameters;

and if the second input parameter is the mandatory input parameter, assigning the second input parameter to the second test data according to the input format to generate a second input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

if the first input parameter is a necessary filling input parameter and the sequence number of the first input parameter is less than or equal to the total number of the necessary filling input parameters, generating the name of the test case based on the interface number, the interface name, the name of the first input parameter and the actual unnecessary information of the first input parameter;

correspondingly, the encoding type in the output parameter corresponding to the first input parameter in the expected result is that the parameter is null.

Optionally, the test case is a reverse test case;

the generating of the input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information includes:

determining an input format of an input parameter based on the request type and the content type; the input format comprises an input parameter name and a format of a corresponding input parameter;

determining third test data which exceed the value range of a third input parameter and accord with the value type of the third input parameter;

if the third input parameter is a mandatory input parameter, assigning the third input parameter to the third test data according to the input format to generate a third input parameter value of the test case;

determining fourth test data based on the corresponding value range and the value type aiming at fourth input parameters except the third input parameters;

and if the fourth input parameter is a mandatory input parameter, assigning the fourth input parameter to the fourth test data according to the input format to generate a fourth input parameter value of the test case.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the attribute information of the input parameter includes:

if the third input parameter is a necessary input parameter and the sequence number of the third input parameter is less than or equal to the total number of the necessary input parameters, generating the name of the test case based on the interface number, the interface name, the name of the third input parameter and the invalid attribute information of the third input parameter;

correspondingly, the encoding type in the output parameter corresponding to the third input parameter in the expected result is invalid.

Optionally, generating the name of the test case based on the interface number, the interface name in the necessary description information, and the type information of the test case includes:

and generating the name of the test case based on the interface number, the interface name and the forward type of the test case.

The device can execute the method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.

Fig. 6 is a schematic structural diagram of an apparatus provided in an embodiment of the present invention, and as shown in fig. 6, the apparatus includes:

one or more processors 610, one processor 610 being exemplified in fig. 6;

a memory 620;

the apparatus may further include: an input device 630 and an output device 640.

The processor 610, the memory 620, the input device 630 and the output device 640 of the apparatus may be connected by a bus or other means, and fig. 6 illustrates the example of connection by a bus.

The memory 620, as a non-transitory computer-readable storage medium, may be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to a test case generation method of an interface in an embodiment of the present invention (for example, the receiving/setting module 510, the first generation module 520, the second generation module 530, and the third generation module 540 shown in fig. 5). The processor 610 executes various functional applications and data processing of the computer device by running the software programs, instructions and modules stored in the memory 620, namely, a test case generation method for implementing an interface of the above method embodiment, that is:

receiving an interface description document, and setting a corresponding number for an interface in the interface description document;

reading necessary description information of an interface in the interface description document, and generating the name of a test case based on an interface number, the name of the interface in the necessary description information, and type information of the test case or attribute information of an input parameter;

generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information;

and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

The memory 620 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the computer device, and the like. Further, the memory 620 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, memory 620 optionally includes memory located remotely from processor 610, which may be connected to the terminal device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.

The input means 630 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the computer apparatus. The output device 640 may include a display device such as a display screen.

An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a test case generation method for an interface according to an embodiment of the present invention:

receiving an interface description document, and setting a corresponding number for an interface in the interface description document;

reading necessary description information of an interface in the interface description document, and generating the name of a test case based on an interface number, the name of the interface in the necessary description information, and type information of the test case or attribute information of an input parameter;

generating an input parameter value of the test case based on the request type, the content type, the input parameter name, whether the input parameter is a necessary input parameter, the value range of the input parameter and the value type in the necessary description information;

and generating an expected result of the test case based on the response time and the output parameters in the necessary description information.

Any combination of one or more computer-readable media may be employed. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.

A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.

Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:端到端自动化测试方法、装置及电子设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!