Test data generation method, device, electronic device and storage medium
By automatically analyzing business logic data, generating scene sets and calculating feasible domain matrix, the problem of insufficient manual experience in test data generation is solved, and high-quality and efficient test data generation is achieved.
Patent Information
- Application Number
- CN202210061332.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-01-19
AI Technical Summary
In the prior art, the generation of test data relies on manual experience, resulting in scenario omissions and unstable test data quality, making it difficult to fully cover the code logic.
By automatically analyzing the input business logic data, extracting the path from the starting node to the end node, generating a scene set, and splitting the logical expressions, calculating the possible solutions of a single expression, and generating test data using a feasible domain matrix.
It realizes automatic and comprehensive generation of test data, avoids the influence of human factors, and improves the quality and generation efficiency of test data.
Smart Images

Figure CN114385511B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing, and in particular to a test data generating method, device, electronic equipment and storage medium. Background Art
[0002] In the testing field, test data is typically generated by testers based on their previous business experience. Because testers struggle to analyze the overall code logic, test data for certain scenarios can be easily missed. Furthermore, the testers' limited understanding of business logic and content, as well as their mastery of testing theory, can easily affect the quality of test data, thus reducing the reliability of software testing. Summary of the Invention
[0003] The purpose of the present invention is to provide a test data generation method, device, electronic device and storage medium, which can automatically analyze the input business logic data to obtain business scenarios, and automatically generate comprehensive and effective test data for each business scenario, which can effectively improve the test data and the efficiency of test data generation.
[0004] To solve the above technical problems, the present invention provides a test data generation method, comprising:
[0005] Obtain input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and an end node, and the directed edges connecting the nodes are logical expressions including test fields;
[0006] Extracting a path from the starting node to the ending node from the input data, and generating a scene set using a logical expression on the same path;
[0007] Splitting the logical expression to obtain a single expression, and generating an expression set using the single expression of the same logical expression; the single expression includes the test field, a constant value, an arithmetic operator, and a relational operator;
[0008] Calculating possible solutions of the test field corresponding to the single expression, and generating a feasible domain matrix of the expression set using possible solutions corresponding to the single expressions included in the same expression set;
[0009] The test data corresponding to the scenario set is generated by utilizing the feasible domain matrix corresponding to the expression set included in the same scenario set.
[0010] Optionally, generating a scene set by using a logical expression on the same path includes:
[0011] generating an initial set for the path using a logical expression on the same path;
[0012] Setting the test fields included in the initial set as fields to be processed, and determining whether there is a contradiction between the value ranges of each of the fields to be processed in different logical expressions of the initial set;
[0013] If so, remove the initial set and the corresponding path;
[0014] If not, the initial set is set as the scene set.
[0015] Optionally, splitting the logical expression to obtain a single expression includes:
[0016] Converting the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are the single expressions or logical operators;
[0017] The single expression is extracted from the node.
[0018] Optionally, calculating possible solutions of the single expression corresponding to the test field includes:
[0019] Determining the number of test fields and relational operator types included in the single expression;
[0020] If the number of the test fields is one and the relational operator type is an equality sign, then using the single expression to calculate possible solutions of the test fields contained in the single expression;
[0021] If the number of the test fields is multiple and the relational operator type is the equal sign, converting the single expression into a linear matrix, and using the linear matrix to calculate possible solutions of the test fields included in the single expression;
[0022] If the number of the test fields is one and the relational operator type is an inequality sign, then using the single expression and a dynamic programming method to calculate possible solutions for the test fields included in the single expression;
[0023] If the number of the test fields is multiple and the relational operator type is the inequality sign, the single expression is converted into a nonlinear matrix, and the possible solutions of the test fields included in the single expression are calculated using the nonlinear matrix and the dynamic programming method.
[0024] Optionally, the generating of test data corresponding to the scenario set by using the feasible domain matrix corresponding to the expression set included in the same scenario set includes:
[0025] Setting the feasible domain matrix corresponding to the expression set included in the same scenario set as the feasible domain matrix to be filtered;
[0026] Calculating a retention degree for each row of data in the feasible domain matrix to be filtered using a neural network, and determining whether the retention degree is greater than a preset threshold;
[0027] If yes, then setting the data corresponding to the retention degree as the initial test data corresponding to the feasible domain matrix to be filtered;
[0028] The test data is generated by using the initial test data corresponding to all the processed feasible domain matrices to be filtered.
[0029] The present invention also provides a test data generating device, comprising:
[0030] An acquisition module is configured to acquire input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and an end node, and the directed edges connecting the nodes are logical expressions including a test field;
[0031] A scene extraction module, configured to extract a path from the start node to the end node from the input data, and generate a scene set using a logical expression on the same path;
[0032] An expression splitting module, configured to split the logical expression into single expressions and generate an expression set using the single expressions of the same logical expression; the single expression includes the test field, a constant value, an arithmetic operator, and a relational operator;
[0033] A possible solution calculation module, configured to calculate possible solutions of the test field corresponding to the single expression, and generate a feasible domain matrix of the expression set using possible solutions corresponding to the single expressions included in the same expression set;
[0034] The test data generation module is used to generate test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set.
[0035] Optionally, the scene extraction module includes:
[0036] An initial set extraction submodule, configured to generate an initial set for the path using a logical expression on the same path;
[0037] a judgment submodule, configured to set the test fields included in the initial set as fields to be processed, and to judge whether there is a contradiction between the value ranges of each of the fields to be processed in different logical expressions of the initial set;
[0038] A removal submodule, for removing the initial set and the corresponding path if yes;
[0039] The scene set extraction submodule is configured to set the initial set as the scene set if no.
[0040] Optionally, the expression splitting module includes:
[0041] A tree structure conversion submodule, configured to convert the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are the single expressions or logical operators;
[0042] The single expression extraction submodule is used to extract the single expression from the node.
[0043] The present invention further provides an electronic device, comprising:
[0044] memory for storing computer programs;
[0045] A processor is configured to implement the test data generating method described above when executing the computer program.
[0046] The present invention also provides a storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are loaded and executed by a processor, the test data generating method described above is implemented.
[0047] The present invention provides a test data generation method, comprising: obtaining input data; the input data is a directed graph, the nodes of the directed graph include preset starting nodes and ending nodes, and the directed edges connecting the nodes are logical expressions including test fields; extracting a path from the starting node to the ending node from the input data, and generating a scenario set using the logical expression on the same path; splitting the logical expression to obtain a single expression, and generating an expression set using the single expression of the same logical expression; the single expression includes the test field, a constant value, an arithmetic operator and a relational operator; calculating possible solutions of the single expression corresponding to the test field, and generating a feasible domain matrix of the expression set using the possible solutions corresponding to the single expression included in the same expression set; and generating test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set.
[0048] It can be seen that the present invention automatically analyzes the input business logic data, automatically extracts the business path from the data according to the starting node and the ending node of the input data, and then obtains the business scenario. It can automatically and comprehensively analyze the code logic and avoid the omission of scenarios caused by manual generation. After obtaining the business scenario, the present invention can automatically refine and split the logical expression involved in the scenario to obtain several single expressions, and use the single expression to calculate the possible solutions of the corresponding test fields, and then use the possible solutions and the correspondence between the logical expression and the single expression to generate a feasible domain matrix for each logical expression. Finally, the matrix can be used to generate comprehensive and effective test data for each business scenario, which can not only avoid the influence of human factors such as the tester's understanding of business logic and business content and the mastery of test theory on the quality of test data, improve the quality of test data, but also improve the efficiency of test data generation. The present invention also provides a test data generation device, an electronic device and a storage medium with the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0050] Figure 1 A flow chart of a test data generating method provided by an embodiment of the present invention;
[0051] Figure 2 A schematic diagram of input data provided by an embodiment of the present invention;
[0052] Figure 3 A schematic diagram of a path provided by an embodiment of the present invention;
[0053] Figure 4 A schematic diagram of a neural network provided by an embodiment of the present invention;
[0054] Figure 5 This is a structural block diagram of a test data generating device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0055] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0056] In related technologies, test data is usually generated by testers based on their previous business experience. Since it is difficult for testers to analyze the code logic from an overall macro perspective, test data in certain scenarios is easily missed. In addition, the testers' understanding of business logic and business content, as well as their mastery of testing theory, can easily affect the quality of test data, thereby reducing the reliability of software testing. In view of this, the present invention provides a test data generation method that can automatically analyze the input business logic data to obtain business scenarios, and automatically generate comprehensive and effective test data for each business scenario, which can effectively improve test data and the efficiency of test data generation. Please refer to Figure 1 , Figure 1 A flow chart of a test data generation method provided by an embodiment of the present invention, the method may include:
[0057] S101. Obtain input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and an end node, and the directed edges connecting the nodes are logical expressions including test fields.
[0058] In the embodiment of the present invention, the input data comes from the actual business logic, and its structure is a directed graph, which includes a preset start node and end node, and the directed edges connecting each node are logical expressions containing test fields. Figure 2 , Figure 2 A schematic diagram of input data provided by an embodiment of the present invention, wherein node_start represents the starting node, node_end represents the ending node, and node1, node2 and other intermediate nodes are ordinary nodes in a directed graph. It should be noted that the embodiment of the present invention does not limit the number of starting nodes and ending nodes, which can be one or more, and can be set according to actual application requirements. It should be noted that the embodiment of the present invention does not limit the specific code form of the input data, and can be set according to actual application requirements. Specifically, the input data may include a graph node set and a graph edge set, wherein the graph node set records all the nodes in the directed graph, and the graph edge set records all the directed edges in the directed graph. In one possible case, the above two sets can be in the form of:
[0059] Graph node collection: scene_node = [node_start, node2, ..., node_end]
[0060] Graph edge collection:
[0061]
[0062] Here, scene_node represents the graph node set, scene_edge represents the graph edge set, nodeN represents the starting point of a directed edge, next_node:nodeM indicates that the directed edge ends at nodeM (nodeN and nodeM are different nodes), and logic:Logic represents the logical expression on the directed edge. Of course, input data can also be entered in other code formats, and the graph node set and graph edge set can also have other formats, which can be set according to actual application requirements.
[0063] Furthermore, the logical expression on the directed edge may include four logical operators: “()” (brackets), “!” (not), “&” (and), and “|” (or), and their operation priorities decrease from left to right. Furthermore, the test field on the logical expression has at least one attribute, value (numeric value), and may also have other attributes such as format (format), type (type), length (length). In addition, the attributes of the test field can participate in the logical operation corresponding to the logical expression, for example, seg3.value>1|seg2.value>seg3.value, where seg2 and seg3 are both fields, and value is a numeric attribute. Furthermore, operation priorities can also be set for various attributes of the test field. For example, in the above example, the operation priorities of the four attributes, format, type, length, and value, decrease from left to right. It should be noted that the embodiment of the present invention does not limit the specific operation form of the above attributes in the logical expression, and can be set according to actual application requirements.
[0064] S102: extracting a path from a start node to an end node from the input data, and generating a scene set using a logical expression on the same path.
[0065] A scenario is a path from the starting node to the ending node in the input data, for example Figure 2 In the example, a scene can be node_start, node1, other nodes in the middle and node_end, such as Figure 3 Specifically, the path and scene set can be represented by the following set:
[0066] scenes=[scene1,scene2,...,sceneN]
[0067] sceneN=[Logic1,Logic2,...,LogicM]
[0068] Where scenes represents input data, sceneN is one of the scenes, and LogicM is the logical expression contained in the scene. Of course, the form of the above set can also be adjusted according to actual application requirements, and the embodiment of the present invention does not limit this. It can be understood that the path should not have branches, that is, a single scene does not contain branches, and sceneN cannot be divided into other scenes. For example, Logic1 in sceneN turns to Logic2 when seg2.value>0, and turns to Logic3 when seg2.value<=0. At this time, a branch will appear in sceneN, which is not allowed in the scene extraction process.
[0069] Furthermore, it is understood that logical expressions within the same scenario set should not be contradictory. For example, if field seg2 is restricted to seg2.value>0 in Logic1 and to seg2.value<-1 in Logic2 of the same scenario set, the two restrictions on seg2 will be contradictory, which will result in the inability to generate valid test data for the scenario set. To avoid this, when extracting a scenario set, the present invention will detect the logical expressions in the set to determine whether these expressions are contradictory. If so, the scenario will be removed; otherwise, the scenario will be retained.
[0070] In one possible scenario, generating a scene set using logical expressions on the same path may include:
[0071] Step 11: Generate an initial set of paths using logical expressions on the same path;
[0072] Step 12: Set the test fields included in the initial set as the fields to be processed, and determine whether there is a conflict in the value range of each field to be processed in different logical expressions of the initial set; if so, proceed to step 13; if not, proceed to step 14;
[0073] Step 13: Remove the initial set and the corresponding path;
[0074] Step 14: Set the initial collection as the scene collection.
[0075] It should be noted that the embodiment of the present invention does not limit the method for determining the conflict relationship, and it can be set according to actual application requirements.
[0076] S103. Split the logical expression into single expressions, and generate an expression set using the single expressions of the same logical expression; the single expression includes a test field, a constant value, an arithmetic operator, and a relational operator.
[0077] This step further breaks down the logical expression into single expressions and reorganizes the processed paths, scene sets, and expression sets into the following format:
[0078] analyzed_scenes=[analysed_scene1,analysed_scene2,...,analysed_sceneN]
[0079] analyzed_sceneN=[analysed_logic1,analysed_logic2,...,analysed_logicM]
[0080] analyzed_logicM=[signal_logic1,signal_logic2,...,signal_logicK]
[0081] Among them, analyzed_scenes represents the processed path set, analyzed_sceneN represents the processed scene set, analyzed_logicM represents the processed expression set, and signal_logicK represents a single expression. A single expression contains a test field, a constant value, an arithmetic operator, and a relational operator. The test field can also have field attributes. It is understandable that the arithmetic operators and relational operators supported by test fields of different attributes and data types may be different, and can be set according to actual application requirements. Specifically, a single expression can be represented by the following equation:
[0082] signal_logicK=segX.properties operate_sign segY.properties compare_sign value operate_sign segZ.properties
[0083] Here, signal_logicK represents a single expression K, segX, segY, and segZ represent test fields, properties represent field attributes, operate_sign represents an arithmetic operator, compare_sign represents a relational operator, and value represents a constant value. It's understandable that the number of test fields in a single expression is not fixed and can be one or more.
[0084] Furthermore, it should be noted that the purpose of splitting the logical expression is not only to extract a single expression, but also to clear the logical operators in the logical expression. The embodiment of the present invention does not limit how to split the logical expression. For example, regular expressions can be used for splitting, or the logical expression can be converted into a tree structure. Taking into account that in practical applications, the writing of regular expressions is relatively difficult and not flexible, the embodiment of the present invention will split the logical expression by converting the logical expression into a tree structure. It is understandable that when performing the tree conversion, the splitting needs to be performed according to the operation priority of the logical operator.
[0085] In one possible scenario, splitting a logical expression into a single expression may include:
[0086] Step 21: Convert the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are single expressions or logical operators;
[0087] Step 22: Extract a single expression from the node.
[0088] In one possible case, the tree structure conversion can be implemented by the following pseudo code:
[0089]
[0090]
[0091] Of course, the tree conversion of logical expressions can also be achieved in other ways. The above pseudo code is only a possible example. The specific implementation method can be designed according to the actual application requirements. The following is a brief introduction to the splitting results of logical expressions based on a specific example. In one possible case, a logical expression is:
[0092] (sd.a.value-1>0&(!(2*sd.a.len+s.value+3>=6&((s.value>7)s.value!=0)&s.value<7|(4*sd.a.len+5*s.len>8)))&())&(s.value=1|s.value+10 / 4>sd.a.value)
[0093] After splitting, the single expressions that can be obtained are:
[0094] sd.a.value-1>0, 2*sd.a.len+s.value+3>=6, s.value>7, s.value! =0, s.value<7, 4*sd.a.len+5*s.len>8, s.value=1, s.value+10 / 4>sd.a.value.
[0095] S104: Calculate possible solutions of a single expression corresponding to a test field, and generate a feasible region matrix of the expression set using possible solutions corresponding to the single expressions included in the same expression set.
[0096] After obtaining a single expression, the possible solutions of the test field can be calculated based on the constraints of the single expression. Specifically, an expression set of the form of the following set can be input:
[0097] analyzed_logicM=[signal_logic1, signal_logic2,..., signal_logicK]
[0098] Then we get the feasible region matrix of the output:
[0099] segs=[seg1, seg2,..., segN]
[0100] values=[
[0101] [value11, value12,...value1N], ......
[0103] [valueM1,valueM2,...valueMN] ]
[0105] Here, segs represents the set of test fields, and values is the required feasible domain. It should be noted that the feasible domain mentioned in this embodiment of the present invention differs from that in mathematics and includes not only numbers but also other data types such as strings, dates, and Booleans.
[0106] For ease of understanding and illustration, this embodiment of the present invention primarily describes the process for determining possible solutions for a numeric test field. Of course, test fields of other types, such as strings, times, and Booleans, can also be used. The solution process is similar to that for numeric fields and can be adjusted based on actual application requirements.
[0107] It should be noted that the method for solving possible solutions to a test field depends on the number of test fields and the type of relational operator in a single expression. When the number and type differ, the solution method changes. Specifically, when a single expression contains only one test field and the relational operator is equal, for example, A = 0, the value of the test field can be directly solved using the expression. When a single expression contains multiple test fields and the relational operator is equal, for example, A + B = 0, the single expression needs to be converted into a linear matrix and the possible solutions to the test field solved using this matrix. When a single expression contains one test field and the relational operator is not equal, for example, A > 0, the single expression is an inequality involving one variable, and dynamic programming is used to solve the single expression to obtain possible solutions to the test field. When a single expression contains multiple test fields and the relational operator is not equal, for example, A + B > 0, the single expression is an inequality involving multiple variables, and the expression needs to be converted into a nonlinear matrix and solved using this matrix and dynamic programming. It should be noted that the inequality sign includes greater than, less than, greater than or equal to, less than or equal to, and not equal to.
[0108] In one possible case, computing possible solutions of a single expression corresponding to a test field may include:
[0109] Step 31: Determine the number of test fields and relational operator types included in a single expression;
[0110] Step 32: If the number of test fields is one and the relational operator type is equal, then use the single expression to calculate possible solutions for the test fields contained in the single expression;
[0111] Step 33: If the number of test fields is multiple and the relational operator type is equal, convert the single expression into a linear matrix, and use the linear matrix to calculate possible solutions for the test fields included in the single expression;
[0112] Step 34: If the number of test fields is one and the relational operator type is inequality, then use a single expression and dynamic programming to calculate possible solutions for the test fields included in the single expression;
[0113] Step 35: If the number of test fields is multiple and the relational operator type is inequality, the single expression is converted into a nonlinear matrix, and the nonlinear matrix and dynamic programming method are used to calculate possible solutions of the test fields included in the single expression.
[0114] After obtaining possible solutions, the possible solutions of the test fields corresponding to the single expressions can be integrated according to the correspondence between the expression set and the single expressions to obtain the feasible domain corresponding to the expression set.
[0115] S105 , generating test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set.
[0116] It is understandable that the feasible domain matrix generated by the feasible solution is usually large in scale and needs to be filtered. In the embodiment of the present invention, a neural network is introduced to perform filtering calculations to improve filtering efficiency. Figure 4 , Figure 4 This is a schematic diagram of a neural network provided by an embodiment of the present invention. The input layer is the value of the field, i.e., each row of data in the row-domain matrix, and the output layer is the retention degree of this row of data. The retention degree can be used to determine whether this set of test data is retained.
[0117] In one possible scenario, generating test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set may include:
[0118] Step 41: setting the feasible domain matrix corresponding to the expression set contained in the same scenario set as the feasible domain matrix to be filtered;
[0119] Step 42: Calculate the retention degree for each row of data in the feasible domain matrix to be filtered using a neural network, and determine whether the retention degree is greater than a preset threshold; if so, proceed to step 43; if not, ignore the data corresponding to the retention degree;
[0120] Step 43: setting the data corresponding to the retention degree as the initial test data corresponding to the feasible region matrix to be filtered;
[0121] Step 44: Generate test data using the initial test data corresponding to all processed feasible domain matrices to be filtered.
[0122] It should be noted that the embodiment of the present invention does not limit the specific filtering process of the neural network, and reference may be made to related technologies of the neural network.
[0123] Based on the above embodiments, the present invention automatically analyzes the input business logic data, automatically extracts the business path from the data according to the starting node and the ending node of the input data, and then obtains the business scenario. It can automatically and comprehensively analyze the code logic and avoid the omission of scenarios caused by manual generation. After obtaining the business scenario, the present invention can automatically refine and split the logical expression involved in the scenario to obtain several single expressions, and use the single expression to calculate the possible solutions of the corresponding test fields, and then use the possible solutions and the correspondence between the logical expression and the single expression to generate a feasible domain matrix for each logical expression. Finally, the matrix can be used to generate comprehensive and effective test data for each business scenario, which can not only avoid the influence of human factors such as the tester's understanding of business logic and business content and the mastery of test theory on the test data quality, improve the test data quality, but also improve the efficiency of test data generation.
[0124] The following introduces a test data generating device, an electronic device, and a storage medium provided by embodiments of the present invention. The test data generating device, the electronic device, and the storage medium described below can correspond to the test data generating method described above.
[0125] Please refer to Figure 5 , Figure 5 This is a structural block diagram of a test data generating device provided by an embodiment of the present invention, which may include:
[0126] Acquisition module 501 is used to acquire input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and end node, and the directed edges connecting the nodes are logical expressions containing test fields;
[0127] A scene extraction module 502 is used to extract a path from a start node to an end node from input data, and generate a scene set using a logical expression on the same path;
[0128] An expression splitting module 503 is used to split the logical expression into single expressions and generate an expression set using the single expressions of the same logical expression; the single expression includes a test field, a constant value, an arithmetic operator and a relational operator;
[0129] Possible solution calculation module 504, used to calculate the possible solutions of a single expression corresponding to the test field, and generate the feasible domain matrix of the expression set using the possible solutions corresponding to the single expressions included in the same expression set;
[0130] The test data generating module 505 is used to generate test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set.
[0131] Optionally, the scene extraction module 502 may include:
[0132] The initial set extraction submodule is used to generate an initial set for the path using the logical expression on the same path;
[0133] The judgment submodule is used to set the test fields included in the initial set as the fields to be processed, and to judge whether there is a contradiction between the value ranges of each field to be processed in different logical expressions of the initial set;
[0134] Remove submodules, used to remove the initial set and corresponding paths if yes;
[0135] The scene set extraction submodule is used to set the initial set as the scene set if not.
[0136] Optionally, the expression splitting module 503 may include:
[0137] The tree structure conversion submodule is used to convert the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are single expressions or logical operators;
[0138] The single expression extraction submodule is used to extract a single expression from a node.
[0139] Optionally, the possible solution calculation module 504 may include:
[0140] The quantity and type determination submodule is used to determine the number of test fields and the type of relational operators contained in a single expression;
[0141] A first calculation submodule is configured to calculate possible solutions of the test field contained in the single expression using a single expression if the number of the test field is one and the relational operator type is an equality sign;
[0142] a second calculation submodule, configured to convert the single expression into a linear matrix if the number of test fields is multiple and the relational operator type is an equality sign, and calculate possible solutions of the test fields included in the single expression using the linear matrix;
[0143] A third calculation submodule is configured to calculate possible solutions for the test field contained in the single expression using a single expression and a dynamic programming method if the number of the test field is one and the relational operator type is an inequality sign;
[0144] The fourth calculation submodule is used to convert the single expression into a nonlinear matrix if there are multiple test fields and the relational operator type is an inequality sign, and use the nonlinear matrix and dynamic programming method to calculate possible solutions of the test fields contained in the single expression.
[0145] Optionally, the test data generating module 505 includes:
[0146] A setting submodule is used to set the feasible domain matrix corresponding to the expression set contained in the same scene set as the feasible domain matrix to be filtered;
[0147] The retention degree calculation submodule is used to calculate the retention degree for each row of data in the feasible domain matrix to be filtered using a neural network, and to determine whether the retention degree is greater than a preset threshold;
[0148] A retention submodule, configured to set the data corresponding to the retention degree as the initial test data corresponding to the feasible domain matrix to be filtered;
[0149] The generation submodule is used to generate test data using the initial test data corresponding to all the processed feasible domain matrices to be filtered.
[0150] An embodiment of the present invention further provides an electronic device, including:
[0151] memory for storing computer programs;
[0152] A processor is configured to implement the steps of the test data generating method described above when executing a computer program.
[0153] Since the embodiments of the electronic device part correspond to the embodiments of the test data generating method part, the embodiments of the electronic device part refer to the description of the embodiments of the test data generating method part, which will not be repeated here.
[0154] An embodiment of the present invention further provides a storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the test data generating method of any of the above embodiments are implemented.
[0155] Since the embodiments of the storage medium part correspond to the embodiments of the test data generating method part, the embodiments of the storage medium part refer to the description of the embodiments of the test data generating method part, which will not be repeated here.
[0156] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.
[0157] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0158] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0159] The test data generation method, device, electronic device and storage medium provided by the present invention are introduced in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A test data generation method, characterized in that: include: Obtain input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and an end node, and the directed edges connecting the nodes are logical expressions including test fields; Extracting a path from the starting node to the ending node from the input data, and generating a scene set using a logical expression on the same path; Splitting the logical expression to obtain single expressions, and generating an expression set using the single expressions of the same logical expression; The single expression includes the test field, a constant value, an arithmetic operator and a relational operator; Calculating possible solutions of the test field corresponding to the single expression, and generating a feasible domain matrix of the expression set using possible solutions corresponding to the single expressions included in the same expression set; Generating test data corresponding to the scenario set using the feasible domain matrix corresponding to the expression set included in the same scenario set; Calculating possible solutions of the single expression corresponding to the test field includes: Determining the number of test fields and relational operator types included in the single expression; If the number of the test fields is one and the relational operator type is an equality sign, then using the single expression to calculate possible solutions of the test fields contained in the single expression; If the number of the test fields is multiple and the relational operator type is the equal sign, converting the single expression into a linear matrix, and using the linear matrix to calculate possible solutions of the test fields included in the single expression; If the number of the test fields is one and the relational operator type is an inequality sign, then using the single expression and a dynamic programming method to calculate possible solutions for the test fields included in the single expression; If the number of the test fields is multiple and the relational operator type is the inequality sign, the single expression is converted into a nonlinear matrix, and the possible solutions of the test fields included in the single expression are calculated using the nonlinear matrix and the dynamic programming method.
2. The test data generation method according to claim 1, wherein: The generating of a scene set by using a logical expression on the same path includes: generating an initial set for the path using a logical expression on the same path; Setting the test fields included in the initial set as fields to be processed, and determining whether there is a contradiction between the value ranges of each of the fields to be processed in different logical expressions of the initial set; If so, remove the initial set and the corresponding path; If not, the initial set is set as the scene set.
3. The test data generation method according to claim 1, wherein: The step of splitting the logical expression to obtain a single expression includes: Converting the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are the single expressions or logical operators; The single expression is extracted from the node.
4. The test data generation method according to any one of claims 1 to 3, characterized in that: The generating of test data corresponding to the scenario set by using the feasible domain matrix corresponding to the expression set included in the same scenario set includes: Setting the feasible domain matrix corresponding to the expression set included in the same scenario set as the feasible domain matrix to be filtered; Calculating a retention degree for each row of data in the feasible domain matrix to be filtered using a neural network, and determining whether the retention degree is greater than a preset threshold; If yes, then setting the data corresponding to the retention degree as the initial test data corresponding to the feasible domain matrix to be filtered; The test data is generated by using the initial test data corresponding to all the processed feasible domain matrices to be filtered.
5. A test data generating device, characterized in that: include: An acquisition module is configured to acquire input data; the input data is a directed graph, the nodes of the directed graph include a preset start node and an end node, and the directed edges connecting the nodes are logical expressions including a test field; A scene extraction module, configured to extract a path from the start node to the end node from the input data, and generate a scene set using a logical expression on the same path; An expression splitting module, configured to split the logical expression into single expressions, and generate an expression set using the single expressions of the same logical expression; The single expression includes the test field, a constant value, an arithmetic operator and a relational operator; A possible solution calculation module, configured to calculate possible solutions of the test field corresponding to the single expression, and generate a feasible domain matrix of the expression set using possible solutions corresponding to the single expressions included in the same expression set; A test data generation module, configured to generate test data corresponding to the scenario set using a feasible domain matrix corresponding to an expression set included in the same scenario set; The possible solution calculation module includes: A quantity and type determination submodule, used to determine the number of test fields and the type of relational operators contained in the single expression; a first calculation submodule, configured to calculate possible solutions of the test field contained in the single expression using the single expression if the number of the test field is one and the relational operator type is an equality sign; a second calculation submodule, configured to, if the number of the test fields is multiple and the relational operator type is the equal sign, convert the single expression into a linear matrix, and calculate possible solutions of the test fields included in the single expression using the linear matrix; a third calculation submodule, configured to calculate possible solutions of the test field contained in the single expression by using the single expression and a dynamic programming method if the number of the test field is one and the relational operator type is an inequality sign; The fourth calculation submodule is used to convert the single expression into a nonlinear matrix if the number of the test fields is multiple and the relational operator type is the inequality sign, and use the nonlinear matrix and the dynamic programming method to calculate the possible solutions of the test fields contained in the single expression.
6. The test data generating device according to claim 5, wherein: The scene extraction module includes: An initial set extraction submodule, configured to generate an initial set for the path using a logical expression on the same path; a judgment submodule, configured to set the test fields included in the initial set as fields to be processed, and to judge whether there is a contradiction between the value ranges of each of the fields to be processed in different logical expressions of the initial set; A removal submodule, for removing the initial set and the corresponding path if yes; The scene set extraction submodule is configured to set the initial set as the scene set if no.
7. The test data generating device according to claim 5, wherein: The expression splitting module includes: A tree structure conversion submodule, configured to convert the logical expressions in the scene set into a tree structure according to the priority of the logical operators; the nodes of the tree structure are the single expressions or logical operators; The single expression extraction submodule is used to extract the single expression from the node.
8. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the test data generating method according to any one of claims 1 to 4 when executing the computer program.
9. A storage medium, characterized in that: The storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the test data generating method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Test case generation method and device
CN110389894A
Test case generation method and device, equipment, medium and program product
CN112783786A