Disclosure of Invention
In view of the above, it is necessary to provide a test case method, an apparatus, a computer device, and a storage medium, which can improve the test efficiency of the interface test.
A test case generation method for interface testing comprises the following steps:
acquiring an interface message;
analyzing the interface message to obtain a boundary value;
obtaining a test value according to the boundary value;
generating an expected result corresponding to the test value;
generating an interface test case; the interface test case includes the test value and the expected result.
In one embodiment, said obtaining a test value from said boundary value comprises:
generating an inside test value and an outside test value; the in-bound test value meets the boundary value; the outlier test value does not meet the boundary value;
and taking the in-bound test value and the out-bound test value as the test values.
In one embodiment, the generating the expected result corresponding to the test value includes:
generating an expected success result for the in-bound test value;
generating an expected failure result for the outlier test value;
taking the expected success result and the expected failure result as the expected result.
In one embodiment, before said obtaining the test value according to the boundary value, the method further comprises:
extracting an interface type from the interface message, and determining a value type corresponding to the interface type;
the generating of the in-bound test value and the out-bound test value includes:
determining an in-bound dereferenceable value within the boundary value and an out-of-bound dereferenceable value outside the boundary value;
determining a target boundary internal dereferencing matched with the dereferencing type, and determining a target boundary external dereferencing matched with the dereferencing type;
and selecting the in-bound test value from the target in-bound retrievable values, and selecting the out-bound test value from the target out-bound retrievable values.
In one embodiment, the generating an interface test case includes:
and adding the test value and the expected result to a preset case template to obtain the interface test case.
In one embodiment, further comprising:
inputting the interface test case to a test interface; the test interface is used for returning an actual result according to the interface test case;
judging whether the actual result is the same as the expected result;
if so, judging that the test interface is normal;
if not, judging that the test interface is abnormal.
A test case generation apparatus comprising:
the message acquisition module is used for acquiring an interface message;
the message analysis module is used for analyzing the interface message to obtain a boundary value;
the test value module is used for obtaining a test value according to the boundary value;
the result generating module is used for generating an expected result corresponding to the test value;
and the case generating module is used for generating an interface test case according to the test value and the expected result.
In one embodiment, further comprising:
the input module is used for inputting the interface test case to the test interface; the test interface is used for returning an actual result according to the interface test case;
the judging module is used for judging whether the actual result is the same as the expected result or not;
the normal judging module is used for judging that the test interface is normal;
and the abnormity judging module is used for judging that the test interface is abnormal.
A computer device comprising a memory storing a computer program and a processor implementing the following steps when the computer program is executed:
acquiring an interface message;
analyzing the interface message to obtain a boundary value;
obtaining a test value according to the boundary value;
generating an expected result corresponding to the test value;
generating an interface test case; the interface test case includes the test value and the expected result.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring an interface message;
analyzing the interface message to obtain a boundary value;
obtaining a test value according to the boundary value;
generating an expected result corresponding to the test value;
generating an interface test case; the interface test case includes the test value and the expected result.
According to the case generation method, the case generation device, the computer equipment and the storage medium, the boundary value is analyzed in the interface message, the test value is obtained according to the boundary value, the expected result corresponding to the test value is generated, the test value and the expected result are adopted to generate the interface test cases, the automatic generation of a batch of interface test cases is realized, even if the data interface is frequently updated, a tester does not need to redesign the test cases, the labor and the time are saved, and the test efficiency of the data interface is improved.
Moreover, the batch interface test cases have higher case coverage rate, and can be tested aiming at extreme case conditions, so that the abnormity of the data interface is more accurately tested, and the test accuracy rate of the data interface is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
Fig. 1 is a test case generation method for a test interface according to an embodiment, including the following steps:
step S110, obtaining an interface message.
The interface message may be a message having a standard message format. For example, a message in JSON (JavaScript Object Notation) format.
It should be noted that the test case generation method in the embodiment of the present application may be applied to a test server. The test server is used for generating a test case. The test server may be implemented as a stand-alone server or as a server cluster of multiple servers.
In specific implementation, the interface message may be acquired according to a data interface to be tested, and the interface message may be input to the test server, so that the test server acquires the interface message.
For example, the acquired interface message is { "username": "string": "0": "100", "userid": "integer": "0": "20"}.
And step S120, analyzing the interface message to obtain a boundary value.
The boundary value may be a minimum threshold and a maximum threshold of the data interface for limiting the input value. For example, the minimum and maximum threshold for the registration interface is 0, 20 characters, and the registration interface can only enter account names within 0-20 characters.
In a specific implementation, the test server may parse the interface message to obtain one or more interface parameters, where the interface parameters may include a boundary value.
For example, parsing the interface message { "username": "string": "0": "100", "userid": "integer": "0": "20" }, two interface parameters are obtained, the interface parameter 01 is [ "username": "string": "0": "100" ], the interface parameter 02 is [ "integer": "0": "20"]. The boundary value of the interface parameter 01 is [0, 100], and the boundary value of the interface parameter 02 is [0, 20 ].
And step S130, obtaining a test value according to the boundary value.
The test value may be a numerical value for testing the data interface.
In a specific implementation, the test server may determine, according to the boundary value, a selectable value within the boundary value and a selectable value outside the boundary value, select a plurality of values from the selectable values within the boundary value, select a plurality of values from the selectable values outside the boundary value, and take the selected values within the boundary value and outside the boundary value as the test values.
For example, a border value of [0, 100], a minimum border value of 0, may be taken to be a value less than 0, such as-5; the maximum boundary value is 100 and may take values greater than 100, such as 150; values within the limits, e.g. 40, 60, etc., are possible. Thus, -5, 150, 40 and 60 were obtained as test values.
Step S140, generating an expected result corresponding to the test value.
The expected result may be a result expected to be returned by the data interface after the test value is input into the data interface.
In a specific implementation, a corresponding test result may be generated for each test value as an expected result. For example, for a test value of "50" within the boundary values, the corresponding expected result is an expected successful result; for a test value of "-5" outside the boundary value, the corresponding expected result is the expected failure result.
Step S150, generating an interface test case; the interface test case includes the test value and the expected result.
In specific implementation, the test values and the corresponding expected results may be added to a preset case template to form a plurality of interface test cases.
According to the technical scheme provided by the embodiment of the application, the boundary value is analyzed in the interface message, the test value is obtained according to the boundary value, the expected result corresponding to the test value is generated, the test value and the expected result are adopted to generate the interface test case, the automatic generation of the batch of interface test cases is realized, even if the data interface is frequently updated, a tester does not need to redesign the test case, the labor and the time are saved, and the test efficiency of the data interface is improved.
Moreover, the batch interface test cases have higher case coverage rate, and can be tested aiming at extreme case conditions, so that the abnormity of the data interface is more accurately tested, and the test accuracy rate of the data interface is improved.
In another embodiment, the step S130 includes:
generating an inside test value and an outside test value; the in-bound test value meets the boundary value; the outlier test value does not meet the boundary value; and taking the in-bound test value and the out-bound test value as the test values.
For example, the boundary values are [0, 100], the minimum boundary value is 0, and the maximum boundary value is 100. The value range conforming to the boundary value is a value between 0 and 100, and a value selected within the value range conforming to the boundary value is used as an in-boundary test value, for example, 40, 60; the range of values that do not fit the boundary values is [ - ∞, 0] and [100, + ∞ ], and the value selected within the range of values that do not fit the boundary values is used as the outlier test value, e.g., -5, 150.
In another embodiment, before said obtaining the test value according to the boundary value, further comprising:
extracting an interface type from the interface message, and determining a value type corresponding to the interface type;
wherein, the value type can be the type of the test value. For example, the value type may be an integer type or a character string type.
In a specific implementation, when the interface packet is parsed, a value type may be extracted from the interface parameter parsed from the interface packet.
For example, parsing the interface message { "username": "string": "0": "100", "userid": "integer": "0": "20" }, two interface parameters are obtained, the interface parameter 01 is [ "username": "string": "0": "100" ], the interface parameters 02 are [ "integer": "0": "20"]. The value type of the interface parameter 01 is string, that is, a character string type. The value type of the interface parameter 02 is integer, i.e. integer type.
The generating of the in-bound test value and the out-bound test value includes:
determining an in-bound dereferenceable value within the boundary value and an out-of-bound dereferenceable value outside the boundary value; determining a target boundary internal dereferencing matched with the dereferencing type, and determining a target boundary external dereferencing matched with the dereferencing type; and selecting the in-bound test value from the target in-bound retrievable values, and selecting the out-bound test value from the target out-bound retrievable values.
In a specific implementation, after the value type is determined, the target intra-range dereferencing matched with the value type can be determined in the intra-range dereferencing, and the target extra-range dereferencing matched with the value type can be determined in the extra-range dereferencing. For example, the boundary value [0, 20] may take any value from 0 to 20, and the value type is an integer type, so the target boundary value [0, 20] may take any integer value from 0 to 20, such as 10, 15, etc.
After the target boundary internal dereferencing value and the target boundary external dereferencing value are determined, values can be randomly selected from the target boundary internal dereferencing value and the target boundary external dereferencing value respectively to serve as an internal testing value and an external testing value.
In another embodiment, the generating the expected result corresponding to the test value includes:
generating an expected success result for the in-bound test value; generating an expected failure result for the outlier test value; taking the expected success result and the expected failure result as the expected result.
The expected result may adopt a custom format, for example, the expected success result is defined as CMB00001, and the expected failure result is defined as CMB 00002.
In particular implementations, expected success results may be generated for the in-bound test values as corresponding expected results. For the outlier test value, an expected failure result may be generated as a corresponding expected result. For example, for an in-bound test value of "-5", CMB00002 is generated as the corresponding expected result.
In practical applications, a result set may be formed by expected results corresponding to a plurality of test values.
In another embodiment, the step S150 includes:
and adding the test value and the expected result to a preset case template to obtain the interface test case.
In practical application, a result set formed by a test value and an expected result can be input into an Automatic Interface Case Design System (AICDS), the test value and the expected result corresponding to the test value are added to a Case template by the AICDS, and Interface test cases are generated in batch.
In another embodiment, the method further comprises:
inputting the interface test case to a test interface; the test interface is used for returning an actual result according to the interface test case; judging whether the actual result is the same as the expected result; if so, judging that the test interface is normal; if not, judging that the test interface is abnormal.
The test interface can be a data interface to be tested.
The actual result may be a test result actually returned by the test interface for the test value.
In specific implementation, the test server can input the interface test case to the test interface, and the automatic test of the data interface can be realized by combining an automatic test framework. The test interface may return a processing result as an actual result for a test value in the interface test case. The test server can compare the actual result with the expected result corresponding to the test value, and if the actual result is the same as the expected result, the test result returned by the test interface for the test value is in accordance with the expectation, and no exception exists. If the two are different, it is indicated that the test result returned by the test interface for the test value is not in accordance with the expectation, and the test interface may have abnormal conditions such as design errors.
According to the technical scheme provided by the embodiment of the application, the interface test is carried out based on the automatically generated batch interface test cases, whether the test interface is abnormal or not is judged according to the comparison result of the actual result and the expected result of the test interface, the test result of the test interface can be quickly obtained without manual intervention in the whole interface test process, and the test efficiency of the interface test is further improved.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in a strict order unless explicitly stated herein, and may be performed in other orders. Moreover, at least a portion of the steps in fig. 1 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed alternately or at least partially with other steps or sub-steps or stages of other steps.
In one embodiment, as shown in fig. 2, a test case generating apparatus is provided, including: a message obtaining module 210, a message analyzing module 220, a test value module 230, a result generating module 240 and a case generating module 250, wherein:
a message obtaining module 210, configured to obtain an interface message;
a message parsing module 220, configured to parse the interface message to obtain a boundary value;
a test value module 230, configured to obtain a test value according to the boundary value;
a result generating module 240, configured to generate an expected result corresponding to the test value;
and a use case generating module 250, configured to generate an interface test case according to the test value and the expected result.
According to the technical scheme provided by the embodiment of the application, the boundary value is analyzed in the interface message, the test value is obtained according to the boundary value, the expected result corresponding to the test value is generated, the interface test cases are generated by adopting the test value and the expected result, the automatic generation of the batch of interface test cases is realized, even if the data interface is frequently updated, testers do not need to redesign the test cases, the labor and the time are saved, and the test efficiency of the data interface is improved.
Moreover, the batch interface test cases have higher case coverage rate, and can be tested aiming at extreme case conditions, so that the abnormity of the data interface is more accurately tested, and the test accuracy rate of the data interface is improved.
In another embodiment, the test value module 230 includes:
the test value generation submodule is used for generating an in-bound test value and an out-bound test value; the in-bound test value meets the boundary value; the outlier test value does not meet the boundary value;
and the test value combining sub-module is used for taking the in-bound test value and the out-bound test value as the test values.
In another embodiment, the result generation module 240 includes:
a success result submodule for generating an expected success result for the in-bound test value;
a failure result submodule for generating an expected failure result of the outlier test value;
a result set submodule for using the expected success result and the expected failure result as the expected result.
In another embodiment, the method further comprises:
the type determining module is used for extracting the interface type from the interface message and determining the value type corresponding to the interface type;
the test value generation submodule includes:
an dereferencing unit for determining an in-bound dereferencing within the boundary value and an out-bound dereferencing outside the boundary value;
the target determining unit is used for determining the target boundary internal dereferencing matched with the dereferencing type and determining the target boundary external dereferencing matched with the dereferencing type;
and the test value selecting unit is used for selecting the in-bound test value from the target in-bound retrievable values and selecting the out-bound test value from the target out-bound retrievable values.
In another embodiment, the use case generation module 250 includes:
and the template adding submodule is used for adding the test value and the expected result to a preset case template to obtain the interface test case.
In another embodiment, further comprising:
the input module is used for inputting the interface test case to the test interface; the test interface is used for returning an actual result according to the interface test case;
the judging module is used for judging whether the actual result is the same as the expected result or not;
the normal judgment module is used for judging that the test interface is normal;
and the abnormity judging module is used for judging that the test interface is abnormal.
According to the technical scheme provided by the embodiment of the application, the interface test is carried out based on the automatically generated batch of interface test cases, whether the test interface is abnormal or not is judged according to the comparison result of the actual result and the expected result of the test interface, the test result of the test interface can be quickly obtained without manual intervention in the whole interface test process, and the test efficiency of the interface test is further improved.
For specific limitations of the test case generation apparatus, see the above limitations on the test case generation method, which are not described herein again. All or part of each module in the test case generation device can be realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, or can be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 3. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operating system and the computer program to run in the non-volatile storage medium. The database of the computer equipment is used for storing data such as interface messages, boundary values, test values, expected results, actual results, interface test cases and the like. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a test case generation method.
Those skilled in the art will appreciate that the configuration shown in fig. 3 is a block diagram of only a portion of the configuration associated with the present application, and does not constitute a limitation on the computing device to which the present application applies, and that a particular computing device may include more or fewer components than shown, or combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory having a computer program stored therein, the processor implementing the following steps when executing the computer program:
acquiring an interface message;
analyzing the interface message to obtain a boundary value;
obtaining a test value according to the boundary value;
generating an expected result corresponding to the test value;
generating an interface test case; the interface test case includes the test value and the expected result.
In one embodiment, the processor, when executing the computer program, further performs the steps of:
generating an inside test value and an outside test value; the within-bound test value meets the boundary value; the outlier test value does not meet the boundary value;
and taking the in-bound test value and the out-bound test value as the test values.
In one embodiment, the processor, when executing the computer program, further performs the steps of:
generating an expected success result for the in-bound test value;
generating an expected failure result for the outlier test value;
taking the expected success result and the expected failure result as the expected result.
In one embodiment, the processor, when executing the computer program, further performs the steps of:
extracting an interface type from the interface message, and determining a value type corresponding to the interface type;
the generating of the in-bound test value and the out-bound test value includes:
determining an in-bound dereferenceable value within the boundary value and an out-of-bound dereferenceable value outside the boundary value;
determining a target boundary internal dereferencing matched with the dereferencing type, and determining a target boundary external dereferencing matched with the dereferencing type;
and selecting the in-bound test value from the target in-bound retrievable values, and selecting the out-bound test value from the target out-bound retrievable values.
In one embodiment, the processor, when executing the computer program, further performs the steps of:
and adding the test value and the expected result to a preset case template to obtain the interface test case.
In one embodiment, the processor, when executing the computer program, further performs the steps of:
inputting the interface test case to a test interface; the test interface is used for returning an actual result according to the interface test case;
judging whether the actual result is the same as the expected result;
if so, judging that the test interface is normal;
if not, judging that the test interface is abnormal.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of:
acquiring an interface message;
analyzing the interface message to obtain a boundary value;
obtaining a test value according to the boundary value;
generating an expected result corresponding to the test value;
generating an interface test case; the interface test case includes the test value and the expected result.
In one embodiment, the computer program when executed by the processor further performs the steps of:
generating an inside test value and an outside test value; the in-bound test value meets the boundary value; the outlier test value does not meet the boundary value;
and taking the in-bound test value and the out-bound test value as the test values.
In one embodiment, the computer program when executed by the processor further performs the steps of:
generating an expected success result for the in-bound test value;
generating an expected failure result for the outlier test value;
taking the expected success result and the expected failure result as the expected result.
In one embodiment, the computer program when executed by the processor further performs the steps of:
extracting an interface type from the interface message, and determining a value type corresponding to the interface type;
determining an in-bound dereferenceable value within the boundary value and an out-of-bound dereferenceable value outside the boundary value;
determining a target boundary internal dereferencing matched with the dereferencing type, and determining a target boundary external dereferencing matched with the dereferencing type;
and selecting the in-bound test value from the target in-bound retrievable value, and selecting the out-bound test value from the target out-bound retrievable value.
In one embodiment, the computer program when executed by the processor further performs the steps of:
and adding the test value and the expected result to a preset case template to obtain the interface test case.
In one embodiment, the computer program when executed by the processor further performs the steps of:
inputting the interface test case to a test interface; the test interface is used for returning an actual result according to the interface test case;
judging whether the actual result is the same as the expected result;
if so, judging that the test interface is normal;
if not, judging that the test interface is abnormal.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent should be subject to the appended claims.