An interface test method and device, computer equipment and storage medium
By specifically setting the mutation probability and mutation method of target data nodes, mutated test cases are generated, which solves the problem of low efficiency caused by random and untargeted data generation in fuzzing, and improves testing efficiency and effectiveness.
Patent Information
- Application Number
- CN202110278889.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-16
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-06-28
AI Technical Summary
In existing fuzzing methods, randomly generated outlier data lacks specificity, resulting in low testing efficiency.
By using the interface identifier of the interface to be tested, the initial test cases are obtained from the database, and the mutation probability and mutation method of the target data node are determined. The initial test cases are then mutated in a targeted manner to generate mutated test cases.
This improves testing efficiency and effectiveness. By controlling the mutation probability and mutation method of data nodes, we can understand the impact of different nodes on the robustness of the interface under test.
Smart Images

Figure CN115080377B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computer, in particular, to an interface testing method and device, computer equipment and storage medium. BACKGROUND
[0002] Fuzz testing is a software testing technique that can be used to find possible program errors by inputting randomly generated data into a program and monitoring the program for abnormal conditions. It is widely used in the field of software testing because it is less costly and more cost-effective than manually constructing abnormal data for testing.
[0003] In existing fuzz testing methods, a large number of abnormal data can be automatically generated for testing, but since the abnormal data is randomly generated, the generated abnormal data is not targeted, resulting in low testing efficiency. SUMMARY
[0004] The present disclosure provides at least an interface testing method and device, computer equipment and storage medium.
[0005] In a first aspect, the present disclosure provides an interface testing method, comprising:
[0006] Based on the interface identifier of the interface to be tested, an initial test case corresponding to the interface to be tested is obtained from a database;
[0007] The mutation probability and mutation method of a target data node to be mutated in the initial test case are determined;
[0008] The initial test case is mutated based on the mutation probability and mutation method of the target data node, to obtain a mutated test case;
[0009] The interface to be tested is tested based on the mutated test case.
[0010] In a possible implementation, the initial test case is mutated based on the mutation probability and mutation method of the target data node, to obtain a mutated test case, comprising:
[0011] The initial test case is mutated based on the mutation probability and mutation method of the target data node, to obtain a first mutated test case;
[0012] The Nth mutated test case is mutated based on the mutation probability and mutation method of the target data node, to obtain an N+1th mutated test case, N being a positive integer greater than or equal to 1.
[0013] In a possible implementation, the test case after the Nth mutation is mutated based on the mutation probability and the mutation method of the target data node in the initial test case to obtain a test case after an (N+1)th mutation, including:
[0014] determining the node type of the target data node corresponding to the mutation node in the test case after the Nth mutation;
[0015] determining the mutation probability and the mutation method of the target data node corresponding to the mutation node as the mutation probability and the mutation method corresponding to the mutation node;
[0016] mutating the test case after the Nth mutation based on the mutation probability and the mutation method corresponding to the mutation node to obtain a test case after an (N+1)th mutation.
[0017] In a possible implementation, the mutation probability and the mutation method of the target data node in the initial test case are determined, including:
[0018] determining the node type of the target data node in the initial test case, where the node type includes a leaf node and a non-leaf node;
[0019] determining the mutation probability and the mutation method matching the node type of the target data node.
[0020] In a possible implementation, the mutation method includes at least one of the following:
[0021] mutating the data structure of the target data node; mutating the data type of the target data node; mutating the node parameter value of the target data node; mutating the number of data nodes included in the test case.
[0022] In a second aspect, the embodiments of the present disclosure further provide an interface testing apparatus, including:
[0023] an acquisition module, configured to acquire an initial test case corresponding to a to-be-tested interface from a database based on an interface identifier of the to-be-tested interface;
[0024] a determination module, configured to determine a mutation probability and a mutation method of a target data node to be mutated in the initial test case;
[0025] a mutation module, configured to mutate the initial test case based on the mutation probability and the mutation method of the target data node to obtain a mutated test case;
[0026] a test module, configured to test the to-be-tested interface based on the mutated test case.
[0027] In a possible implementation, the variation module, when performing variation on the initial test case based on the variation probability and the variation method of the target data node in the initial test case, is configured to:
[0028] perform variation on the initial test case based on the variation probability and the variation method of the target data node in the initial test case to obtain a test case after first variation;
[0029] perform variation on the test case after the Nth variation based on the variation probability and the variation method of the target data node in the initial test case to obtain a test case after (N+1)th variation, where N is a positive integer greater than or equal to 1.
[0030] In a possible implementation, the variation module, when performing variation on the test case after the Nth variation based on the variation probability and the variation method of the target data node in the initial test case to obtain a test case after (N+1)th variation, is configured to:
[0031] determine the node type of the target data node corresponding to the variation node in the test case after the Nth variation;
[0032] determine the variation probability and the variation method of the target data node corresponding to the variation node as the variation probability and the variation method corresponding to the variation node;
[0033] perform variation on the test case after the Nth variation based on the variation probability and the variation method corresponding to the variation node to obtain the test case after the (N+1)th variation.
[0034] In a possible implementation, the determination module, when determining the variation probability and the variation method of the target data node in the initial test case, is configured to:
[0035] determine the node type of the target data node in the initial test case, where the node type includes a leaf node and a non-leaf node;
[0036] determine the variation probability and the variation method matching the node type of the target data node.
[0037] In a possible implementation, the variation method includes at least one of the following:
[0038] performing variation on a data structure of the target data node; performing variation on a data type of the target data node; performing variation on a node parameter value of the target data node; and performing variation on a number of data nodes included in a test case.
[0039] In a third aspect, the embodiments of the present disclosure further provide a computer device, comprising a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the computer device is running, the processor communicates with the memory through the bus, and the machine readable instructions are executed by the processor to perform the steps of the first aspect or any possible implementation manner of the first aspect.
[0040] In a fourth aspect, the embodiments of the present disclosure further provide a computer readable storage medium, which stores a computer program, when the computer program is executed by a processor, the steps of the first aspect or any possible implementation manner of the first aspect are performed.
[0041] The interface test method and device, computer device and storage medium provided by the embodiments of the present disclosure first acquire the initial test case corresponding to the to-be-tested interface from the database based on the interface identifier of the to-be-tested interface, and determine the mutation probability and mutation method of the target data node to be mutated in the initial test case; the initial test case is mutated based on the mutation probability and mutation method of the target data node, to obtain the mutated test case. In this way, the mutation probability and mutation method of the target data node can be set specifically, so that the specific mutation of the data node can be realized. The mutated test case obtained based on this method is used to test the to-be-tested interface. In this way, the influence of different data nodes on the robustness of the to-be-tested interface can be understood by controlling the mutation probability and mutation method of the data node, and the test efficiency and test effect of the to-be-tested interface are improved.
[0042] In order to make the above objectives, characteristics and advantages of the present disclosure more apparent, the following will describe preferred embodiments in detail, and the accompanying drawings will be described as follows. BRIEF DESCRIPTION OF DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings needed to be used in the embodiments. The drawings herein are incorporated into the specification and form a part of the specification, which show the embodiments consistent with the present disclosure, and are used to explain the technical solutions of the present disclosure together with the specification. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be considered as a limitation to the scope, and other related drawings can also be obtained by those skilled in the art without creative labor.
[0044] Figure 1 A flowchart of an interface test method provided by the embodiments of the present disclosure is shown;
[0045] Figure 2A flow chart of a method for mutating a test case after the Nth mutation in an interface test method provided by an embodiment of the present disclosure is shown.
[0046] Figure 3 A schematic diagram of an interface test device provided by an embodiment of the present disclosure is shown.
[0047] Figure 4 A structural schematic diagram of a computer device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0048] To make the objectives, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure and are not all the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the claimed present disclosure, but only represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0049] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0050] The term "and / or" herein is only used to describe an association relationship, which means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B and C can mean including any one or more elements selected from the set consisting of A, B and C.
[0051] It is found through research that in the existing fuzz testing method, although a large number of abnormal data can be automatically generated for testing, since the abnormal data is randomly generated, the generated abnormal data is not targeted, resulting in low efficiency of testing.
[0052] Based on the above research, the present disclosure provides an interface test method, device, computer equipment and storage medium. First, based on the interface identifier of the interface to be tested, the initial test case corresponding to the interface to be tested is obtained from the database, and the mutation probability and mutation method of the target data node to be mutated in the initial test case are determined. Based on the mutation probability and mutation method of the target data node in the initial test case, the initial test case is mutated to obtain the mutated test case. In this way, by setting the mutation probability and mutation method of the target data node, the targeted mutation of the node can be realized. Based on the mutated test case obtained by this method, the interface to be tested is tested. In this way, by controlling the mutation probability and mutation method of the node, the influence of different nodes on the robustness of the interface to be tested can be understood, and the test efficiency and test effect of the interface to be tested are improved.
[0053] To facilitate the understanding of the present embodiment, first, a kind of interface test method disclosed in the present embodiment is introduced in detail, and the execution subject of the interface test method provided by the present embodiment is generally computer equipment with certain computing power, which includes, for example: terminal equipment or server or other processing equipment, terminal equipment can be user equipment (User Equipment, UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (Personal Digital Assistant, PDA), handheld device, computing device, vehicle-mounted device, wearable device, etc. In some possible implementation ways, the interface test method can be realized by the way that processor calls computer readable instructions stored in memory.
[0054] To facilitate the understanding of the present embodiment, first, the application scenario of a kind of interface test method disclosed in the present embodiment is introduced. In a possible application scenario, when performing interface test, interface test data can be generated by changing sending request to detect the robustness of the application program interface (Application Programming Interface, API, hereinafter referred to as interface) of server. For example, an interface test script can be run on the client, which can modify the request sent by the client and send the modified request to the server to test the robustness of the interface of the server under different requests. The specific execution steps of the interface test script when modifying the request sent by the client can be referred to Figure 1 And subsequent specific operation, which will not be expanded here.
[0055] Specifically, the development code of the interface of the server contains a declaration of a plurality of operation parameters, the declaration of the operation parameters is used to indicate parameters required to be contained in the instruction of the request when the request is initiated to the interface, for example, the declaration of the operation parameters declares that when the request is initiated to the interface 1 (i.e., the interface 1 is called), the instruction of the request needs to contain three parameters A1, B1 and C1, then the interface test script for testing the interface 1 needs to include specific assignments of the three parameters A1, B1 and C1, for example, it can contain "A2: 1", "B2: 2" and "C2: 3", wherein in the interface test script, A2, B2 and C2 are data nodes, and the three parameters A1, B1 and C1 correspond to the three data nodes A2, B2 and C2 one by one. When the interface 1 processes the interface test script, the specific assignments of the three data nodes A2, B2 and C2 can be processed according to the processing method of the three parameters A1, B1 and C1 in the development code of the interface 1, and the processing result of the interface test script is obtained.
[0056] In actual application, the processing result of the interface test script by the interface can be determined by monitoring the running of the program corresponding to the interface. Exemplarily, the program exception corresponding to the changed sending request can be a server error, that is, the corresponding display of the client is "server error, error code 500", indicating that an error occurs in the server at this time.
[0057] In another possible application scenario, when the interface is tested, the proxy server can be set to intercept the request sent by the client, change the request data in the request, and then send the changed request data to the server to test the interface of the server.
[0058] In specific implementation, the above operation can be implemented through a man-in-the-middle attack (MITM), and the principle is that the man-in-the-middle, i.e., the proxy server, intercepts the request when the client initiates the request, and sends the modified request to the server. The man-in-the-middle attack can refer to the method shown in Figure 1 and subsequent specific operations, which will not be described here.
[0059] In another possible application scenario, the data returned by the server to the client can also be intercepted, and then the intercepted data is mutated and sent to the client to test the stability of the client. Specifically, the method of mutating the intercepted data can also refer to the method shown in Figure 1 .
[0060] The interface test method provided by the present disclosure will be introduced below taking the test of the interface of the server as an example.
[0061] Referring to Figure 1 As shown in a flowchart of an interface test method provided by an embodiment of the present disclosure, the method comprises steps S101-S104, wherein:
[0062] S101: Based on the interface identifier of the interface to be tested, the initial test case corresponding to the interface to be tested is obtained from the database.
[0063] S102: The mutation probability and mutation method of the target data node to be mutated in the initial test case are determined.
[0064] S103: Based on the mutation probability and mutation method of the target data node in the initial test case, the initial test case is mutated to obtain a mutated test case.
[0065] S104: Based on the mutated test case, the interface to be tested is tested.
[0066] The various steps and corresponding implementation methods in the embodiments of the present disclosure will be described in detail below.
[0067] For S101, the initial test case can be obtained from the database, and can also be manually written by the tester. For example, the operation parameter declaration of the interface to be tested contains four operation parameters, and the tester can write the initial test case according to the four operation parameters. The interface to be tested can be used to process the initial test case after being called. The interface to be tested can process the data node carried by the initial test case after being called, and send the returned data obtained after processing to the corresponding calling party according to the returned data format.
[0068] Here, it should be noted that the operation parameter declaration of the interface to be tested can include optional operation parameter declaration and non-optional operation parameter declaration. The initial test case includes a data node corresponding to each optional operation parameter, or can also include a data node corresponding to a non-optional operation parameter.
[0069] In a specific implementation, after obtaining the initial test case of the interface to be tested, the mutation probability and mutation method of the target data node to be mutated in the initial test case can be determined according to S102, and the specific method is as follows.
[0070] The target data node has a one-to-one correspondence with the operation parameter in the to-be-tested interface that has a testing requirement. The selection of a specific target data node can be selected by a tester according to a testing requirement. It is assumed that the to-be-tested interface includes three operation parameters A, B, and C, and the instruction code includes three data nodes "A: 1", "B: 2", and "C: 3". The operation parameter included in the to-be-tested interface has a one-to-one correspondence with the data node included in the instruction code of the interface request. When the basic function of the test interface is tested, all data nodes corresponding to the operation parameters can be selected as the target data node. When a special function, such as a new function test, is tested, a data node corresponding to a new operation parameter can be selected as the target data node for focused testing.
[0071] In actual application, the to-be-tested interface can include multiple operation parameters. When the to-be-tested interface processes the test case, the value of the data node in the test case is actually assigned to the corresponding operation parameter. Then, the to-be-tested interface can process based on the assigned operation parameter to test the to-be-tested interface.
[0072] In a possible application scenario, the target data node can be set according to the operation parameter of the to-be-tested interface. For example, if the to-be-tested interface has no new operation parameter, the to-be-tested interface includes operation parameter 1, operation parameter 2, and operation parameter 3. Then, the data nodes corresponding to operation parameter 1, operation parameter 2, and operation parameter 3 in the initial test case are all selected as the target data node. If the target data node has a new operation parameter, for example, the original to-be-tested interface includes operation parameter 1, operation parameter 2, and operation parameter 3, and the new to-be-tested interface includes operation parameter 1, operation parameter 2, operation parameter 3, and operation parameter 4 after the interface function is upgraded. The data node corresponding to the new operation parameter 4 in the initial test case can be set as the target data node. Then, the robustness of the new operation parameter 4 is tested.
[0073] The mutation probability is the probability of mutation of the current target data node when the test case is mutated. For example, the mutation probability of data node 1 is 10%, which means that data node 1 has a 10% probability of mutation when the test case is mutated once.
[0074] The mutation method includes mutating the data structure of the target data node; and / or mutating the data type of the target data node; and / or mutating the node parameter value of the target data node; and / or mutating the number of data nodes included in the test case.
[0075] The data structure of the target data node is mutated, for example, the data structure corresponding to the current data exchange format is a JSON (JavaScript Object Notation, JS object notation) structure, and the data structure mutation can be generated by setting a non-JSON structure;
[0076] The data type of the target data node is mutated, for example, the current integer type data int and string type data string can be converted to other type data to generate data type mutation;
[0077] The node parameter value of the target data node is mutated, for example, the parameter value corresponding to the data node can be set to null value, None value, empty string, ultra-long string, abnormal string, empty list, empty dictionary, no return value, 0 or 1, etc. Special value, 255 or 0.0, etc. Boundary value to generate parameter value mutation;
[0078] The number of data nodes contained in the test case is mutated, for example, the current data node can be deleted, the current data node can be repeated, and other data nodes can be added to increase or decrease the number of data nodes, thereby generating data node number mutation.
[0079] In a specific implementation, the mutation probability and mutation method of the target data node in the initial test case can be determined by the following two methods:
[0080] Method A, obtaining the mutation probability and mutation method set in advance for each target data node in the initial test case.
[0081] Due to different test requirements, the focus of the test is different, different target data nodes can be set different mutation probability and mutation method, the target data node of the key test can be set higher mutation probability and more mutation method, the target data node of non-key test is set lower mutation probability and less mutation method, or the mutation probability of non-key test target data node is set to 0, that is, the non-key test data node is not mutated, so that it remains in the original state in the whole test process.
[0082] Alternatively, due to different influence degrees of different target data nodes on the interface to be tested, for example, the mutation probability of some target data nodes can be high, but the influence on the interface to be tested is not great, that is, it does not affect the normal processing of the data by the interface to be tested; the mutation probability of some target data nodes can be low, but the influence on the interface to be tested can be great, therefore, based on the historical mutation of each data node when the interface to be tested appears abnormal, the mutation probability and mutation method of different target data nodes can be set.
[0083] Method B, first determine the node type of the target data node in the initial test case, and then determine the mutation probability and mutation method matching the node type of the target data node.
[0084] Here, the node type includes a leaf node and a non-leaf node. The leaf node is a terminal node in a data structure, that is, a node without subsequent other nodes. The non-leaf node is all other nodes except the leaf node.
[0085] In specific implementation, after identifying the node type, a first mutation probability and a first mutation method can be set for the leaf node, and a second mutation probability and a second mutation method can be set for the non-leaf node. For example, the target data node is data node 1, data node 2, data node 3, and data node 4. It is identified that data node 1 and data node 2 are leaf nodes, and data node 3 and data node 4 are non-leaf nodes. The first mutation probability for the leaf node can be set to 40%, and a number of mutation methods are selected from the above mutation methods to form the first mutation method. The second mutation probability for the non-leaf node can be set to 20%, and a number of mutation methods are selected from the above mutation methods to form the second mutation method. The first mutation method can be the same as the second mutation method.
[0086] It should be noted that since mutation itself is specific and random, it is difficult to completely control. In order to improve the stability of the mutation process and reduce the occurrence of abnormal conditions in the mutation process, the mutation probability of the leaf node can be set to be relatively high, and the mutation probability of the non-leaf node can be set to be relatively low, so as to avoid abnormal conditions such as excessive or insufficient number of data nodes caused by repeated mutation of the non-leaf node associated with the leaf node and the corresponding leaf node, and excessive mutation of the non-leaf node.
[0087] In specific implementation, after determining the mutation probability and mutation method of the target data node in the initial test case, the initial test case can be mutated according to S103 to obtain a mutated test case. The specific method is as follows.
[0088] S103: mutate the initial test case based on the mutation probability and mutation method of the target data node in the initial test case to obtain a mutated test case.
[0089] In a possible implementation, in the case of mutating the initial test case based on the mutation probability and mutation method of the target data node in the initial test case, for the first mutation, the initial test case can be mutated based on the mutation probability and mutation method of the target data node in the initial test case to obtain a test case after the first mutation.
[0090] In a specific implementation, the process of interface testing is as follows: mutation-test-mutation-test-...
[0091] Here, the target data node in the initial test case is first mutated based on the mutation probability and mutation method of the target data node, to obtain a test case after the first mutation.
[0092] For other mutations after the first mutation, the test case after the Nth mutation can be mutated based on the mutation probability and mutation method of the target data node in the initial test case to obtain a test case after the (N+1)th mutation, where N is a positive integer greater than or equal to 1.
[0093] Here, since more than one mutation is often performed in the entire testing process, to improve the difference between the mutated test case and the initial test case, the (N+1)th mutation can be performed on the test case after the Nth mutation. Here, N can be set to a maximum value, such as 499, so that after 500 mutations and corresponding tests, the entire test of the interface to be tested can be completed; or a corresponding mutation stop condition can be set, such as 10 abnormal situations appearing in the test result, and then the current mutation can be stopped, and the abnormal situations appearing can be sorted into a corresponding test report and sent to the tester.
[0094] In a possible implementation, in the case of mutating the initial test case based on the mutation probability and mutation method of the target data node in the initial test case, for the first mutation, the initial test case can be mutated based on the mutation probability and mutation method of the target data node in the initial test case to obtain a test case after the first mutation. Figure 2 The test case after the Nth mutation can be mutated based on the mutation probability and mutation method of the target data node in the initial test case to obtain a test case after the (N+1)th mutation, as shown in FIG. 8.
[0095] S201: Determine the node type of the target data node corresponding to the mutation node in the test case after the Nth mutation.
[0096] Here, since the number of nodes is mutated in the mutation method, the number of data nodes can increase.
[0097] Exemplarily, the target data nodes are target data node 1, target data node 2, target data node 3, and target data node 4, the mutation nodes in the test case after the Nth mutation are mutation node 1, mutation node 2, mutation node 3, mutation node 4, mutation node 5, and mutation node 6, and it can be determined through the mutation process query that the mutation node 1, the mutation node 2, the mutation node 3, and the mutation node 4 correspond to the target data node 1, the target data node 2, the target data node 3, and the target data node 4 respectively, and the mutation node 5 and the mutation node 6 are newly generated nodes through mutation. The newly generated data nodes are obviously not the target data nodes set before the interface test starts. Since the newly generated mutation nodes do not have corresponding target data nodes, the to-be-tested interface cannot process the newly generated mutation nodes when the to-be-tested interface is tested, and thus the newly generated mutation nodes are invalid mutation. Therefore, determining the mutation nodes corresponding to the target data nodes can avoid the waste of time and computing resources caused by invalid mutation of the newly generated mutation nodes, and improve the efficiency of interface testing through the pertinence of data node mutation.
[0098] S202: Determine the mutation probability and the mutation method of the target data node corresponding to the mutation node as the mutation probability and the mutation method corresponding to the mutation node.
[0099] It should be noted that since the number of nodes in the mutation varies, the number of data nodes may increase. In this case, the type of the original target data node may change from a leaf node to a non-leaf node. Since the mutation is not completely controllable, it is not possible to determine in advance whether the mutation node obtained through mutation is a leaf node or a non-leaf node. Therefore, the node type of the target data node corresponding to each mutation node needs to be determined.
[0100] Exemplarily, still taking the target data nodes as target data node 1, target data node 2, target data node 3, and target data node 4, and the mutation nodes in the test case after the Nth mutation as mutation node 1, mutation node 2, mutation node 3, mutation node 4, mutation node 5, and mutation node 6, it can be determined through the mutation process query that the target data nodes corresponding to the mutation node 1, the mutation node 2, the mutation node 3, and the mutation node 4 are target data node 1, target data node 2, target data node 3, and target data node 4 respectively, and the node types of the target data nodes are leaf node, leaf node, non-leaf node, and non-leaf node respectively.
[0101] Specifically, when the variation process is queried, the target data node corresponding to the current variation node can be determined according to the variation process from back to front, for example, the variation process of the variation node 1 is queried, and the state of the node before variation is traced back from back to front to find the data node 1 in the initial test case, and then it is determined whether the data node is the target data node according to the state at that time. According to the query, it is known that the node 1 in the initial test case is the target data node, and the data node is a leaf node, so the target data node corresponding to the variation node 1 is the leaf node.
[0102] Here, when determining the node type of the target data node corresponding to the variation node, in one possible implementation, the node type of the target data node in the initial test case can be determined before the initial test case is varied, and in another possible implementation, the target data nodes in the initial test case can be traversed after the initial test case is varied, the variation node corresponding to each target data node in the varied test case is determined, and then the node type of the target data node corresponding to each variation node is determined based on the node type of the target data node in the initial test case.
[0103] In one possible implementation, the variation probability and the variation method corresponding to the variation node can be found based on the correspondence between the node type and the variation probability and the variation method set in advance. The variation probability and the variation method correspond to the node type of the target data node corresponding to the current variation node.
[0104] For example, the first variation probability set for the leaf node is 40%, the first variation probability corresponds to the first variation method, the second variation probability set for the non-leaf node is 20%, the second variation probability corresponds to the second variation method, the target data node 1 is a leaf node, and the variation node 1 corresponds to the target data node 1. The variation probability of the variation node 1 can be the first variation probability 40% set for the target data node 1, and the variation method corresponds to the first variation method corresponding to the first variation probability.
[0105] Here, it should be noted that when determining the variation probability and the variation method corresponding to the variation node, it is irrelevant whether the variation node itself is a leaf node or a non-leaf node, but it is relevant whether the target data node corresponding to the variation node is a leaf node or a non-leaf node.
[0106] S203: Based on the variation probability and the variation method corresponding to the variation node, the test case after the Nth variation is varied to obtain the test case after the N+1th variation.
[0107] The mutation method can be multiple, and when mutation is performed based on the mutation probability and the mutation method, any one of the multiple mutation methods can be selected to mutate the test case. In a specific implementation, after obtaining the mutated test case, the to-be-tested interface can be tested based on the mutated test case.
[0108] Specifically, the corresponding interface request can be sent to the to-be-tested interface based on the mutated test case, and the test result can be recorded by monitoring the operation of the interface.
[0109] In a possible implementation, after the to-be-tested interface is tested based on the mutated test case, a test report corresponding to the to-be-tested interface can be generated based on the test result and the mutated test case.
[0110] In a specific implementation, the test result obtained based on the current mutated test case can also be counted to obtain a test report for the to-be-tested interface after all mutations and tests are performed.
[0111] For example, when the current mutated test case is used for testing and it is monitored that the program corresponding to the interface crashes, the current mutated test case and the test result that the program crashes can be encapsulated to generate an exception record, and further, the test process can be continued, and the subsequent exception and the corresponding exception record can be counted, and finally, the test report containing all the exception records can be displayed on the client, so that the user can have a clearer understanding of the test result of the to-be-tested interface.
[0112] The interface testing method provided by the embodiments of the present disclosure first obtains the initial test case corresponding to the to-be-tested interface from the database based on the interface identifier of the to-be-tested interface, and determines the mutation probability and the mutation method of the target data node to be mutated in the initial test case; the initial test case is mutated based on the mutation probability and the mutation method of the target data node to obtain a mutated test case. In this way, by setting the mutation probability and the mutation method of the target data node, targeted mutation of the data node can be achieved. The to-be-tested interface is tested based on the mutated test case obtained by this method. In this way, by controlling the mutation probability and the mutation method of the data node, the influence of different data nodes on the robustness of the to-be-tested interface can be understood, and the testing efficiency and the testing effect of the to-be-tested interface are improved.
[0113] Those skilled in the art can understand that the sequence of writing each step in the above method of the specific embodiment does not mean a strict execution sequence and does not constitute any limitation on the implementation process, and the specific execution sequence of each step should be determined by its function and possible internal logic.
[0114] Based on the same inventive concept, the interface testing device corresponding to the interface testing method is also provided in the embodiments of the disclosure. Since the principle of solving problems of the device in the embodiments of the disclosure is similar to the above-mentioned interface testing method of the embodiments of the disclosure, the implementation of the device can be referred to the implementation of the method, and the repeated parts will not be described here.
[0115] Referring to Figure 3 FIG. 1 shows a schematic diagram of an interface testing device provided by the embodiments of the disclosure. The device comprises an acquisition module 301, a determination module 302, a variation module 303, and a testing module 304.
[0116] The acquisition module 301 is configured to acquire an initial test case corresponding to a to-be-tested interface from a database based on an interface identifier of the to-be-tested interface.
[0117] The determination module 302 is configured to determine a variation probability and a variation method of a target data node to be varied in the initial test case.
[0118] The variation module 303 is configured to vary the initial test case based on the variation probability and the variation method of the target data node in the initial test case to obtain a varied test case.
[0119] The testing module 304 is configured to test the to-be-tested interface based on the varied test case.
[0120] In a possible implementation, the variation module 303, when varying the initial test case based on the variation probability and the variation method of the target data node in the initial test case to obtain a varied test case, is configured to:
[0121] vary the initial test case based on the variation probability and the variation method of the target data node in the initial test case to obtain a first varied test case;
[0122] vary the Nth varied test case based on the variation probability and the variation method of the target data node in the initial test case to obtain an (N+1)th varied test case, where N is a positive integer greater than or equal to 1.
[0123] In a possible implementation, the variation module 303, when performing variation on the test case after the Nth variation based on the variation probability and the variation method of the target data node in the initial test case to obtain the test case after the (N+1)th variation, is configured to:
[0124] determine the node type of the target data node corresponding to the variation node in the test case after the Nth variation;
[0125] determine the variation probability and the variation method of the target data node corresponding to the variation node as the variation probability and the variation method corresponding to the variation node;
[0126] perform variation on the test case after the Nth variation based on the variation probability and the variation method corresponding to the variation node to obtain the test case after the (N+1)th variation.
[0127] In a possible implementation, the determination module 302, when determining the variation probability and the variation method of the target data node in the initial test case, is configured to:
[0128] determine the node type of the target data node in the initial test case, where the node type includes a leaf node and a non-leaf node;
[0129] determine the variation probability and the variation method matching the node type of the target data node.
[0130] In a possible implementation, the variation method includes at least one of the following:
[0131] performing variation on a data structure of the target data node, performing variation on a data type of the target data node, performing variation on a node parameter value of the target data node, and performing variation on the number of data nodes included in the test case.
[0132] The interface testing apparatus provided in the embodiments of the present disclosure first acquires the initial test case corresponding to the to-be-tested interface from the database based on the interface identifier of the to-be-tested interface, and determines the variation probability and the variation method of the target data node to be varied in the initial test case. Then, the initial test case is varied based on the variation probability and the variation method of the target data node to obtain a varied test case. In this way, the variation probability and the variation method of the target data node can be set in a targeted manner to realize targeted variation of the data node. The varied test case obtained based on this method is used to test the to-be-tested interface. In this way, the variation probability and the variation method of the data node can be controlled to understand the influence of different data nodes on the robustness of the to-be-tested interface, thereby improving the test efficiency and test effect of the to-be-tested interface.
[0133] The description of the processing flow of each module in the device and the interaction flow between the modules can refer to the related description in the above method embodiments, and will not be described in detail here.
[0134] Based on the same technical concept, the embodiments of the present disclosure also provide a computer device. Referring to Figure 4 As shown in the structure schematic diagram of the computer device 400 provided by the embodiments of the present disclosure, it includes a processor 401, a memory 402, and a bus 403. The memory 402 is used to store execution instructions, including an internal memory 4021 and an external memory 4022; the internal memory 4021 is also called an internal memory, used to temporarily store operation data in the processor 401 and data exchanged with the external memory 4022 such as a hard disk, the processor 401 exchanges data with the external memory 4022 through the internal memory 4021, and when the computer device 400 is running, the processor 401 and the memory 402 communicate through the bus 403, so that the processor 401 executes the following instructions:
[0135] Based on the interface identifier of the interface to be tested, the initial test case corresponding to the interface to be tested is obtained from the database;
[0136] Determine the mutation probability and mutation method of the target data node to be mutated in the initial test case;
[0137] Based on the mutation probability and mutation method of the target data node in the initial test case, the initial test case is mutated to obtain a mutated test case;
[0138] Based on the mutated test case, the interface to be tested is tested.
[0139] In a possible implementation, in the instructions of the processor 401, the mutation of the initial test case based on the mutation probability and mutation method of the target data node in the initial test case to obtain a mutated test case includes:
[0140] Based on the mutation probability and mutation method of the target data node in the initial test case, the initial test case is mutated to obtain a first mutated test case;
[0141] Based on the mutation probability and mutation method of the target data node in the initial test case, the Nth mutated test case is mutated to obtain an N+1th mutated test case, N is a positive integer greater than or equal to 1.
[0142] In a possible implementation, the instructions of the processor 401 include: determining a mutation probability and a mutation method of a target data node in the initial test case, and performing mutation on the Nth mutation test case based on the mutation probability and the mutation method of the target data node, to obtain an (N+1)th mutation test case.
[0143] determining a node type of the target data node corresponding to the mutation node in the Nth mutation test case;
[0144] determining the mutation probability and the mutation method of the target data node corresponding to the mutation node as a mutation probability and a mutation method corresponding to the mutation node;
[0145] performing mutation on the Nth mutation test case based on the mutation probability and the mutation method corresponding to the mutation node, to obtain an (N+1)th mutation test case.
[0146] In a possible implementation, the instructions of the processor 401 include: determining a mutation probability and a mutation method of a target data node in the initial test case, and performing mutation on the Nth mutation test case based on the mutation probability and the mutation method of the target data node, to obtain an (N+1)th mutation test case.
[0147] determining a node type of the target data node in the initial test case, the node type including a leaf node and a non-leaf node;
[0148] determining a mutation probability and a mutation method matching the node type of the target data node.
[0149] In a possible implementation, the instructions of the processor 401 include: the mutation method includes at least one of the following:
[0150] performing mutation on a data structure of the target data node; performing mutation on a data type of the target data node; performing mutation on a node parameter value of the target data node; and performing mutation on a number of data nodes included in the test case.
[0151] The embodiment of the present disclosure further provides a computer readable storage medium, which stores a computer program. The computer program is run by a processor to perform the steps of the interface test method in the method embodiment.
[0152] The embodiment of the present disclosure further provides a computer program product, which carries a program code. The program code includes instructions that can be used to perform the steps of the interface test method in the method embodiment. For details, refer to the method embodiment, which will not be described here.
[0153] The computer program product can be implemented by hardware, software or a combination thereof. In an optional embodiment, the computer program product is embodied in a computer storage medium. In another optional embodiment, the computer program product is embodied in a software product, such as a software development kit (SDK) or the like.
[0154] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here. In several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some communication interfaces, devices or units, which can be electrical, mechanical or other forms.
[0155] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment scheme.
[0156] In addition, each functional unit in each embodiment of the present disclosure can be integrated in one processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit.
[0157] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a nonvolatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present disclosure essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0158] Finally, it should be noted that: the above-described embodiments are only specific embodiments of the present disclosure, used to illustrate the technical solutions of the present disclosure, and not to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art who is familiar with the technical field of the present disclosure can make modifications or easily think of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed by the present disclosure, or make equivalent replacements to some of the technical features. The modifications, changes or replacements do not cause the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. An interface test method characterized by, The method comprises the steps of: obtaining an initial test case corresponding to a to-be-tested interface from a database based on an interface identifier of the to-be-tested interface; determining a mutation probability and a mutation method of a target data node to be mutated in the initial test case; wherein the mutation probability represents the possibility of the current target data node being mutated when the test case is mutated; mutating the initial test case based on the mutation probability and the mutation method of the target data node in the initial test case to obtain a mutated test case; wherein the mutation of the initial test case at least includes deleting a current data node, repeating the current data node, and adding other data nodes; sending an interface request corresponding to the mutated test case to the to-be-tested interface, and recording the test result by monitoring the operation of the to-be-tested interface; wherein the determination of the mutation probability and the mutation method of the target data node in the initial test case comprises: determining the node type of the target data node in the initial test case, wherein the node type includes a leaf node and a non-leaf node, the leaf node is a terminal node without subsequent other nodes in a data structure, and the non-leaf node is other nodes in the data structure except the leaf node; determining a first mutation probability and a first mutation method matched with the leaf node, and a second mutation probability and a second mutation method matched with the non-leaf node, wherein the first mutation probability is greater than the second mutation probability.
2. The method of claim 1, wherein, The mutation of the initial test case based on the mutation probability and the mutation method of the target data node in the initial test case to obtain a mutated test case comprises: mutating the initial test case based on the mutation probability and the mutation method of the target data node in the initial test case to obtain a first mutated test case; mutating the Nth mutated test case based on the mutation probability and the mutation method of the target data node in the initial test case to obtain an (N+1)th mutated test case, wherein N is a positive integer greater than or equal to 1.
3. The method of claim 2, wherein, The mutation of the Nth mutated test case based on the mutation probability and the mutation method of the target data node in the initial test case to obtain an (N+1)th mutated test case comprises: determining the node type of the target data node corresponding to the mutation node in the Nth mutated test case; determining the mutation probability and the mutation method of the target data node corresponding to the mutation node as the mutation probability and the mutation method corresponding to the mutation node; mutating the Nth mutated test case based on the mutation probability and the mutation method corresponding to the mutation node to obtain an (N+1)th mutated test case.
4. The method according to any one of claims 1 to 3, characterized in that, The mutation method comprises at least one of the following: mutating the data structure of the target data node; mutating the data type of the target data node; and mutating the node parameter value of the target data node.
5. An interface testing device, characterized by The method comprises the steps of: obtaining an initial test case corresponding to a to-be-tested interface from a database based on an interface identifier of the to-be-tested interface; The determining module is configured to determine a mutation probability and a mutation method of a target data node to be mutated in the initial test case; the mutation probability indicates a possibility of the current target data node being mutated when the test case is mutated. The mutation module is configured to mutate the initial test case based on the mutation probability and the mutation method of the target data node in the initial test case, to obtain a mutated test case. The mutation module is configured to at least perform one of deleting the current data node, repeating the current data node, and adding other data nodes when mutating the initial test case. The test module is configured to send a corresponding interface request to the interface to be tested based on the mutated test case, and record a test result by monitoring a running state of the interface to be tested. The determining module is further configured to determine a node type of the target data node in the initial test case, the node type including a leaf node and a non-leaf node, the leaf node being a terminal node without any subsequent node in a data structure, and the non-leaf node being any node other than the leaf node in the data structure; determine a first mutation probability and a first mutation method matched with the leaf node, and a second mutation probability and a second mutation method matched with the non-leaf node, wherein the first mutation probability is greater than the second mutation probability.
6. The apparatus of claim 5, wherein, The mutation module is configured to: mutate the initial test case based on the mutation probability and the mutation method of the target data node in the initial test case, to obtain a first mutated test case; mutate an Nth mutated test case based on the mutation probability and the mutation method of the target data node in the initial test case, to obtain an (N+1)th mutated test case, N being a positive integer greater than or equal to 1.
7. The apparatus of claim 6, wherein, The mutation module is configured to: determine a node type of a target data node corresponding to a mutation node in the Nth mutated test case; determine the mutation probability and the mutation method of the target data node corresponding to the mutation node as a mutation probability and a mutation method corresponding to the mutation node; mutate the Nth mutated test case based on the mutation probability and the mutation method corresponding to the mutation node, to obtain the (N+1)th mutated test case.
8. A computer device, comprising: The computer device comprises a processor, a memory, and a bus, the memory stores machine readable instructions executable by the processor, the processor and the memory communicate through the bus when the computer device is running, and the machine readable instructions are executed by the processor to perform steps of the interface test method according to any one of claims 1 to 4. 9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program performs the steps of the interface test method according to any one of claims 1 to 4 when the computer program is run by the processor.
Citation Information
Patent Citations
Automatic generation method and system for test case
CN108595341A
Interface test method and device, equipment and medium
CN110196813A
Industrial control protocol test method and system, electronic equipment and storage medium
CN111123888A