CN114385511A - Test data generation method and device, electronic equipment and storage medium - Google Patents
Test data generation method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114385511A CN114385511A CN202210061332.5A CN202210061332A CN114385511A CN 114385511 A CN114385511 A CN 114385511A CN 202210061332 A CN202210061332 A CN 202210061332A CN 114385511 A CN114385511 A CN 114385511A
- Authority
- CN
- China
- Prior art keywords
- expression
- test
- logic
- test data
- scene
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a test data generation method, which can automatically analyze input service logic data, automatically extract a service path in the data according to a starting node and an ending node of the input data so as to obtain a service scene, automatically and comprehensively analyze code logic, and avoid scene omission caused by manual generation; after the service scenes are obtained, the logic expression related to the scenes can be automatically refined and split to obtain a plurality of single expressions, the possible solutions of the corresponding test fields are calculated by using the single expressions, and then the comprehensive and effective test data are generated for each service scene by using the possible solutions and the corresponding relation among the service scenes, the logic expressions and the single expressions, so that the quality of the test data can be effectively improved, and meanwhile, the generation efficiency of the test data can also be improved. The invention also provides a test data generation device, electronic equipment and a storage medium, which have the beneficial effects.
Description
Technical Field
The present invention relates to the field of software testing, and in particular, to a method and an apparatus for generating test data, an electronic device, and a storage medium.
Background
In the field of testing, test data is typically generated by a tester based on past business experience. Because testers are difficult to analyze from the overall macroscopic code logic, test data in certain scenes are easy to be omitted; in addition, the degree of understanding of the service logic and the service content and the degree of mastering the test theory by the tester are easy to influence the quality of the test data, so that the reliability of the software test is easy to reduce.
Disclosure of Invention
The invention aims to provide a test data generation method, a test data generation device, electronic equipment and a storage medium, which can automatically analyze input service logic data to obtain service scenes, automatically generate comprehensive and effective test data for each service scene, and effectively improve the generation efficiency of the test data and the test data.
In order to solve the above technical problem, the present invention provides a test data generation method, including:
acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and end nodes, and directed edges connecting the nodes are logic expressions comprising test fields;
extracting paths from the starting node to the ending node from the input data, and generating a scene set by using a logic expression on the same path;
splitting the logic expression to obtain a single expression, and generating an expression set by using the single expression of the same logic expression; the single expression contains the test field, constant values, arithmetic operators and relational operators;
calculating possible solutions corresponding to the test fields of the single expressions, and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set;
and generating test data corresponding to the scene set by using a feasible domain matrix corresponding to an expression set contained in the same scene set.
Optionally, the generating a scene set by using the logical expressions on the same path includes:
generating an initial set for the path by using a logic expression on the same path;
setting the test fields contained in the initial set as fields to be processed, and judging whether the value ranges of the fields to be processed in different logic expressions of the initial set have contradiction;
if so, removing the initial set and the corresponding path;
if not, setting the initial set as the scene set.
Optionally, the splitting the logic expression to obtain a single expression includes:
converting the logic expressions in the scene set into a tree structure according to the priority of the logic operators; the nodes of the tree structure are the single expression or the logical operator;
extracting the single expression from the node.
Optionally, the calculating a possible solution of the test field corresponding to the single expression includes:
determining the number of test fields and the type of a relational operator contained in the single expression;
if the number of the test fields is one and the type of the relational operator is equal sign, calculating possible solutions of the test fields contained in the single expression by using the single expression;
if the number of the test fields is multiple and the type of the relational operator is the equal sign, converting the single expression into a linear matrix, and calculating possible solutions of the test fields contained in the single expression by using the linear matrix;
if the number of the test fields is one and the type of the relational operator is an unequal number, calculating possible solutions of the test fields contained in the single expression by using the single expression and a dynamic programming method;
if the number of the test fields is multiple and the type of the relational operator is the unequal sign, converting the single expression into a nonlinear matrix, and calculating possible solutions of the test fields contained in the single expression by using the nonlinear matrix and the dynamic programming method.
Optionally, the generating test data corresponding to the scene set by using the feasible domain matrix corresponding to the expression set included in the same scene set includes:
setting the feasible domain matrix corresponding to the expression set contained in the same scene set as a feasible domain matrix to be filtered;
calculating a retention degree for each row of data in the feasible region matrix to be filtered by utilizing a neural network, and judging whether the retention degree is greater than a preset threshold value;
if so, setting the data corresponding to the retention degree as initial test data corresponding to the to-be-filtered feasible domain matrix;
and generating the test data by using the initial test data corresponding to all the processed feasible region matrixes to be filtered.
The present invention also provides a test data generating apparatus, including:
the acquisition module is used for acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and end nodes, and directed edges connecting the nodes are logic expressions comprising test fields;
the scene extraction module is used for extracting a path from the starting node to the ending node from the input data and generating a scene set by using a logic expression on the same path;
the expression splitting module is used for splitting the logic expressions to obtain a single expression and generating an expression set by using the single expression of the same logic expression; the single expression contains the test field, constant values, arithmetic operators and relational operators;
the possible solution calculation module is used for calculating the possible solutions of the test fields corresponding to the single expressions and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set;
and the test data generation module is used for generating test data corresponding to the scene set by using the feasible domain matrix corresponding to the expression set contained in the same scene set.
Optionally, the scene extraction module includes:
the initial set extraction submodule is used for generating an initial set for the path by using the logic expression on the same path;
the judgment submodule is used for setting the test fields contained in the initial set as fields to be processed and judging whether the value ranges of the fields to be processed in different logic expressions of the initial set have contradiction;
a removing submodule, configured to remove the initial set and the corresponding path if the initial set and the corresponding path are the same;
and the scene set extraction submodule is used for setting the initial set as the scene set if the initial set is not the scene set.
Optionally, the expression splitting module includes:
the tree structure transformation module is used for transforming the logic expressions in the scene set into a tree structure according to the priority of the logic operator; the nodes of the tree structure are the single expression or the logical operator;
and the single expression extraction submodule is used for extracting the single expression from the node.
The present invention also provides an electronic device comprising:
a memory for storing a computer program;
a processor for implementing the test data generation method as described above when executing the computer program.
The invention also provides a storage medium, wherein the storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by a processor, the test data generation method is realized.
The invention provides a test data generation method, which comprises the following steps: acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and end nodes, and directed edges connecting the nodes are logic expressions comprising test fields; extracting paths from the starting node to the ending node from the input data, and generating a scene set by using a logic expression on the same path; splitting the logic expression to obtain a single expression, and generating an expression set by using the single expression of the same logic expression; the single expression contains the test field, constant values, arithmetic operators and relational operators; calculating possible solutions corresponding to the test fields of the single expressions, and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set; and generating test data corresponding to the scene set by using a feasible domain matrix corresponding to an expression set contained in the same scene set.
Therefore, the method and the device automatically analyze the input business logic data, automatically extract the business path in the data according to the initial node and the end node of the input data, further obtain the business scene, automatically and comprehensively analyze the code logic, and avoid scene omission caused by manual generation; after a service scene is obtained, the invention can automatically refine and split the logic expression related to the scene to obtain a plurality of single expressions, calculate the possible solutions of the corresponding test fields by using the single expressions, further generate a feasible domain matrix for each logic expression by using the possible solutions and the corresponding relation between the logic expressions and the single expressions, and finally generate comprehensive and effective test data for each service scene by using the matrix, thereby not only avoiding the influence of artificial factors such as the understanding degree of a tester on the service logic and the service content and the mastering degree of a test theory on the quality of the test data, improving the quality of the test data, but also improving the generation efficiency of the test data. The invention also provides a test data generation device, electronic equipment and a storage medium, which have the beneficial effects.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of a test data generation method according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating an input data according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a path provided by an embodiment of the present invention;
FIG. 4 is a diagram illustrating a neural network according to an embodiment of the present invention;
fig. 5 is a block diagram of a test data generating apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the related art, test data is generally generated by a tester based on past business experiences. Because testers are difficult to analyze from the overall macroscopic code logic, test data in certain scenes are easy to be omitted; in addition, the degree of understanding of the service logic and the service content and the degree of mastering the test theory by the tester are easy to influence the quality of the test data, so that the reliability of the software test is easy to reduce. In view of this, the present invention provides a test data generating method, which can automatically analyze input service logic data to obtain service scenarios, and automatically generate comprehensive and effective test data for each service scenario, so as to effectively improve the generation efficiency of the test data and the test data. Referring to fig. 1, fig. 1 is a flowchart of a test data generating method according to an embodiment of the present invention, where the method includes:
s101, acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and ending nodes, and directed edges connecting the nodes are logic expressions comprising test fields.
In the embodiment of the invention, the input data come from actual business logic, the structure of the input data is a directed graph and comprises a preset starting node and a preset ending node, and simultaneously, directed edges connecting all the nodes are logic expressions comprising test fields. Referring to fig. 2, fig. 2 is a schematic diagram of input data according to an embodiment of the present invention, where node _ start represents a start node, node _ end represents an end node, and node1, node2 and other nodes in the middle are common nodes in a directed graph. It should be noted that, the number of the start node and the end node is not limited in the embodiments of the present invention, and may be one or multiple, and may be set according to the 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 the actual application requirements. Specifically, the input data may include a set of graph nodes and a set of graph edges, where the set of graph nodes records all nodes in the directed graph, and the set of graph edges records all directed edges in the directed graph. In one possible case, the two sets may be in the form of:
and (3) graph node set: scene _ node [ [ node _ start, node 2. ], node _ end ]
And (3) drawing edge set:
the scene _ node represents a graph node set, the scene _ edge represents a graph edge set, the node N represents a starting point of the directed edge, the next _ node: node M represents that an end point of the directed edge is node M (the node N and the node M are different nodes), and the Logic: Logic is used for representing a Logic expression on the directed edge. Of course, the input data can also be input in other code forms, and the graph node set and the graph edge set can also have other forms and can be set according to the actual application requirements.
Further, the logical expression on a directed edge may contain "()" (brackets), "! Four logical operators of "(not)," & "(and) and" | "(or), the operation priority of which is sequentially reduced from left to right. Furthermore, the test field on the logical expression at least has an attribute of value, and further may also have other attributes such as format, type, length, and the like, and furthermore, the attribute of the test field may 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 attribute. Further, operation priorities may also be set for various attributes of the test field, for example, in the above example, the operation priorities of the four attributes of format, type, length, and value decrease sequentially 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 logic expression, and can be set according to the actual application requirements.
S102, extracting paths from the starting node to the ending node from the input data, and generating a scene set by using a logic expression on the same path.
A scenario is a path from a start node to an end node in input data, for example, in the example of fig. 2, a scenario may be node _ start, node1, other nodes in the middle, and node _ end, as shown in fig. 3. Specifically, the path and scene set can be represented by the following set:
scenes=[scene1,scene2,...,sceneN]
sceneN=[Logic1,Logic2,...,LogicM]
wherein, scenes represents input data, sceneN is one of the scenes, and LogicM is a logic expression included in the scene. Of course, the form of the set may also be adjusted according to the actual application requirements, which is not limited in the embodiment of the present invention. It is understood that the path should not have branches, i.e. a single scene does not contain branch cases, and sceneN cannot be subdivided into other scenes, for example, Logic1 in sceneN goes to Logic2 when seg2.value >0, and goes to Logic3 when seg2.value < >0, at which time branches will occur in sceneN, which is not allowed in the scene extraction process.
Further, it can be understood that no contradiction should occur in the logical expressions in the same scene set, for example, the field seg2 is limited to seg2.value >0 in Logic1 and is limited to seg2.value < -1 in Logic2 of the same scene set, at which time the two restrictions regarding seg2 will contradict, which in turn will result in that no valid test data can be generated for the scene set. In order to avoid the situation, when a scene set is extracted, the invention detects the logic expressions in the set, determines whether the expressions have contradiction conditions, if so, removes the scene, otherwise, keeps the scene.
In one possible case, generating the scene set by using the logic expression on the same path may include:
step 11: generating an initial set for the path by using a logic expression on the same path;
step 12: setting the test fields contained in the initial set as fields to be processed, and judging whether the value ranges of each field to be processed in different logic expressions of the initial set have contradiction; if yes, go to step 13; if not, entering step 14;
step 13: removing the initial set and the corresponding path;
step 14: the initial set is set as a scene set.
It should be noted that, the embodiment of the present invention does not limit the determination manner of the contradiction relationship, and may be set according to the actual application requirement.
S103, splitting the logic expression to obtain a single expression, and generating an expression set by using the single expression of the same logic expression; the single expression contains test fields, constant values, arithmetic operators, and relational operators.
In the step, the logic expression is further subdivided into single expressions, and the processed path, scene set and expression set are rearranged into the following forms:
analysed_scenes=[analysed_scene1,analysed_scene2,...,analysed_sceneN]
analysed_sceneN=[analysed_logic1,analysed_logic2,...,analysed_logicM]
analysed_logicM=[signal_logic1,signal_logic2,...,signal_logicK]
wherein analyzed _ scenes represents a set of processed paths, analyzed _ scene represents a set of processed scenes, analyzed _ logcM represents a set of processed expressions, and signal _ logcK represents a single expression. A single expression contains test fields, constant values, arithmetic operators, and relational operators, and test fields may also have field attributes. It can be understood that the arithmetic operator and the relational operator that can be supported by the test fields of different attributes and data types may be different, and may be set according to the actual application requirements. Specifically, the single expression can be represented by the following equation:
signal_logicK=segX.properties operate_sign segY.properties compare_sign value operate_sign segZ.properties
wherein, signal _ logicK represents a single expression K, segX, segY and segZ represent test fields, properties represent field properties, operation _ sign represents an arithmetic operator, composition _ sign represents a relational operator, and value represents a constant value. It is understood that the number of test fields contained in a single expression is not fixed, and may be one or more.
Furthermore, it should be noted that the purpose of splitting the logic expression is to extract a single expression, and to remove the logic operator in the logic expression. The embodiment of the invention does not limit how to split the logic expression, for example, the logic expression can be split by using a regular expression, and the logic expression can also be converted into a tree structure. In consideration of the fact that in practical application, the regular expression is difficult to write and is not flexible, the embodiment of the invention splits the logic expression in a mode of converting the logic expression into a tree structure. It can be understood that, when performing tree transformation, splitting is performed according to the operation priority of the logical operator.
In one possible case, splitting the logic expression into a single expression may include:
step 21: converting the logic expressions in the scene set into a tree structure according to the priority of the logic operators; the nodes of the tree structure are single expressions or logical operators;
step 22: a single expression is extracted from the node.
In one possible scenario, the transformation of the tree structure may be implemented by the following pseudo code:
of course, the tree transformation of the logic expression may also be implemented in other manners, the above pseudo code is only one possible example, and the specific implementation manner may be designed according to the actual application requirements. The splitting result of the logic expression is briefly described below based on a specific example. In one possible scenario, a logical expression is:
(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)
after splitting, the single expression that can be obtained is:
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。
s104, calculating possible solutions corresponding to the test fields of the single expressions, and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set.
After the single expression is obtained, possible solutions for the test field may be calculated based on the constraints of the single expression. Specifically, a set of expressions in the form of the following set may be input:
analysed_logicM=[signal_logic1,signal_logic2,...,signal_logicK]
and further obtaining an output feasible domain matrix:
segs=[seg1,seg2,...,segN]
values=[
[value11,value12,...value1N],
......
[valueM1,valueM2,...valueMN]
]
wherein segs represents a test field set, and values is a required feasible field set. It should be noted that the possible fields and the mathematical differences mentioned in the embodiments of the present invention may include not only number type (number), but also string (string), time (date), boolean (boolean), and other data types.
For ease of understanding and explanation, embodiments of the present invention will be described primarily with reference to possible solution solving procedures for the number type (number) test fields. Of course, the test field may have other types, such as string type, time, boolean, etc., and the solving process is similar to the number type, and may be adjusted according to the actual application requirement.
It should be noted that the solution of the possible solutions of the test fields is related to the number of test fields and the type of the relational operator included in the single expression, and when the number and the type are different, the solution is changed. Specifically, when the single expression only includes one test field and the relational operator is an equal sign, for example, a is 0, the value of the test field may be directly obtained through the expression; when the single expression includes a plurality of test fields and the relational operator is an equal sign, for example, a + B is 0, at this time, the single expression needs to be converted into a linear matrix, and a possible solution of the test fields is solved through the matrix; when the single expression comprises a test field and the relational operator is an unequal sign, for example, A is greater than 0, the single expression is an inequality comprising a variable, and at the moment, the single expression is required to be solved by using a dynamic programming method to obtain a possible solution of the test field; when the single expression includes a plurality of test fields and the relational operator is an unequal sign, for example, a + B >0, the single expression is an inequality including a plurality of variables, and at this time, the expression needs to be converted into a nonlinear matrix and solved by using the matrix and a dynamic programming method. It is to be noted that the inequality numbers include greater than, less than, greater than or equal to, less than or equal to, and not equal to.
In one possible case, computing possible solutions for a single expression corresponding to a test field may include:
step 31: determining the number of test fields and the type of a relational operator contained in a single expression;
step 32: if the number of the test fields is one and the type of the relational operator is equal sign, calculating the possible solution of the test fields contained in the single expression by using the single expression;
step 33: if the number of the test fields is multiple and the type of the relational operator is equal sign, converting the single expression into a linear matrix, and calculating the possible solution of the test fields contained in the single expression by using the linear matrix;
step 34: if the number of the test fields is one and the type of the relational operator is an unequal number, calculating possible solutions of the test fields contained in the single expression by using the single expression and a dynamic programming method;
step 35: if the number of the test fields is multiple and the type of the relational operator is not equal, converting the single expression into a nonlinear matrix, and calculating the possible solution of the test fields contained in the single expression by utilizing the nonlinear matrix and a dynamic programming method.
After the possible solutions are obtained, the possible solutions of the test fields corresponding to the single expressions can be integrated according to the corresponding relation between the expression set and the single expressions, and the feasible domain corresponding to the expression set is obtained.
And S105, generating test data corresponding to the scene set by using the feasible domain matrix corresponding to the expression set contained in the same scene set.
It will be appreciated that the feasible domain matrices generated from the feasible solutions are typically large in size and require filtering. In the embodiment of the invention, in order to improve the filtering efficiency, a neural network is introduced for filtering calculation. Referring to fig. 4, fig. 4 is a schematic diagram of a neural network according to an embodiment of the present invention. The input layer is the value of the field, namely, each row of data in the row domain matrix, and the output layer is the retention degree of the row of data, and whether the group of test data is retained or not can be determined according to the retention degree.
In a possible case, generating test data corresponding to a scene set by using a feasible domain matrix corresponding to an expression set included in the same scene set may include:
step 41: setting a feasible domain matrix corresponding to an expression set contained in the same scene set as a feasible domain matrix to be filtered;
step 42: calculating the retention degree for each row of data in the feasible region matrix to be filtered by utilizing a neural network, and judging whether the retention degree is greater than a preset threshold value or not; if yes, go to step 43; if not, ignoring the data corresponding to the retention;
step 43: setting data corresponding to the retention degree as initial test data corresponding to the feasible domain matrix to be filtered;
step 44: and generating test data by using the initial test data corresponding to all the processed feasible region matrixes to be filtered.
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.
Based on the embodiment, the method and the device automatically analyze the input business logic data, automatically extract the business path in the data according to the starting node and the ending node of the input data, further obtain the business scene, can automatically and comprehensively analyze the code logic, and can avoid scene omission caused by manual generation; after a service scene is obtained, the invention can automatically refine and split the logic expression related to the scene to obtain a plurality of single expressions, calculate the possible solutions of the corresponding test fields by using the single expressions, further generate a feasible domain matrix for each logic expression by using the possible solutions and the corresponding relation between the logic expressions and the single expressions, and finally generate comprehensive and effective test data for each service scene by using the matrix, thereby not only avoiding the influence of artificial factors such as the understanding degree of a tester on the service logic and the service content and the mastering degree of a test theory on the quality of the test data, improving the quality of the test data, but also improving the generation efficiency of the test data.
The following describes a test data generating apparatus, an electronic device, and a storage medium according to embodiments of the present invention, and the test data generating apparatus, the electronic device, and the storage medium described below and the test data generating method described above may be referred to in correspondence with each other.
Referring to fig. 5, fig. 5 is a block diagram of a test data generating apparatus according to an embodiment of the present invention, where the apparatus may include:
an obtaining module 501, configured to obtain input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and ending nodes, and directed edges connecting the nodes are logic expressions comprising test fields;
a scene extraction module 502, configured to extract a path from a start node to an end node from input data, and generate a scene set by using a logical expression on the same path;
the expression splitting module 503 is configured to split the logic expressions to obtain single expressions, and generate an expression set by using the single expressions of the same logic expression; the single expression comprises a test field, a constant value, an arithmetic operator and a relational operator;
a possible solution calculation module 504, configured to calculate possible solutions for the test fields corresponding to the single expression, and generate a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions included in the same expression set;
the test data generating module 505 is configured to generate test data corresponding to a scene set by using a feasible domain matrix corresponding to an expression set included in the same scene set.
Optionally, the scene extraction module 502 may include:
the initial set extraction submodule is used for generating an initial set for the path by using the logic expression on the same path;
the judgment submodule is used for setting the test fields contained in the initial set as fields to be processed and judging whether the value ranges of the fields to be processed in different logic expressions of the initial set have contradiction;
a removing submodule, configured to remove the initial set and the corresponding path if the initial set and the corresponding path are the same;
and the scene set extraction submodule is used for setting the initial set as a scene set if the initial set is not the scene set.
Optionally, the expression splitting module 503 may include:
the tree structure transformation module is used for transforming the logic expressions in the scene set into a tree structure according to the priority of the logic operator; the nodes of the tree structure are single expressions or logical operators;
and the single expression extraction submodule is used for extracting the single expression from the node.
Optionally, the possible solution calculation module 504 may include:
the quantity and type determining submodule is used for determining the quantity of the test fields and the type of the relational operator contained in the single expression;
the first calculation submodule is used for calculating possible solutions of the test fields contained in the single expression by using the single expression if the number of the test fields is one and the type of the relational operator is an equal sign;
the second calculation submodule is used for converting the single expression into a linear matrix if the number of the test fields is multiple and the type of the relational operator is equal sign, and calculating the possible solution of the test fields contained in the single expression by using the linear matrix;
the third calculation sub-module is used for calculating possible solutions of the test fields contained in the single expression by using the single expression and a dynamic programming method if the number of the test fields is one and the type of the relational operator is an unequal number;
and the fourth calculation submodule is used for converting the single expression into a nonlinear matrix if the number of the test fields is multiple and the type of the relational operator is an unequal number, and calculating the possible solutions of the test fields contained in the single expression by utilizing the nonlinear matrix and a dynamic programming method.
Optionally, the test data generating module 505 includes:
the setting submodule is used for setting the feasible domain matrix corresponding to the expression set contained in the same scene set as the feasible domain matrix to be filtered;
the retention degree calculation operator module is used for calculating the retention degree for each row of data in the feasible region matrix to be filtered by utilizing the neural network and judging whether the retention degree is greater than a preset threshold value or not;
the retention submodule is used for setting the data corresponding to the retention degree as the initial test data corresponding to the feasible region matrix to be filtered if the retention submodule is used for setting the data corresponding to the retention degree as the initial test data corresponding to the feasible region matrix to be filtered;
and the generation submodule is used for generating test data by utilizing the initial test data corresponding to all the processed feasible domain matrixes to be filtered.
An embodiment of the present invention further provides an electronic device, including:
a memory for storing a computer program;
a processor for implementing the steps of the test data generation method as described above when executing the computer program.
Since the embodiment of the electronic device portion corresponds to the embodiment of the test data generation method portion, please refer to the description of the embodiment of the test data generation method portion for the embodiment of the electronic device portion, and details are not repeated here.
The embodiment of the present invention further provides a storage medium, where a computer program is stored on the storage medium, and when the computer program is executed by a processor, the steps of the test data generation method according to any of the above embodiments are implemented.
Since the embodiment of the storage medium portion and the embodiment of the test data generation method portion correspond to each other, please refer to the description of the embodiment of the test data generation method portion for the embodiment of the storage medium portion, which is not repeated here.
The embodiments are described in a progressive manner in the specification, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The test data generation method, the test data generation device, the electronic device and the storage medium provided by the invention are described in detail above. The principles and embodiments of the present invention are explained herein using specific examples, which are presented only to assist in understanding the method and its core concepts. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.
Claims (10)
1. A method for generating test data, comprising:
acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and end nodes, and directed edges connecting the nodes are logic expressions comprising test fields;
extracting paths from the starting node to the ending node from the input data, and generating a scene set by using a logic expression on the same path;
splitting the logic expression to obtain a single expression, and generating an expression set by using the single expression of the same logic expression; the single expression contains the test field, constant values, arithmetic operators and relational operators;
calculating possible solutions corresponding to the test fields of the single expressions, and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set;
and generating test data corresponding to the scene set by using a feasible domain matrix corresponding to an expression set contained in the same scene set.
2. The method of generating test data according to claim 1, wherein generating the scene set using the logical expressions on the same path includes:
generating an initial set for the path by using a logic expression on the same path;
setting the test fields contained in the initial set as fields to be processed, and judging whether the value ranges of the fields to be processed in different logic expressions of the initial set have contradiction;
if so, removing the initial set and the corresponding path;
if not, setting the initial set as the scene set.
3. The method of claim 1, wherein splitting the logical expression into a single expression comprises:
converting the logic expressions in the scene set into a tree structure according to the priority of the logic operators; the nodes of the tree structure are the single expression or the logical operator;
extracting the single expression from the node.
4. The method of claim 1, wherein computing the possible solutions for the test fields corresponding to the single expression comprises:
determining the number of test fields and the type of a relational operator contained in the single expression;
if the number of the test fields is one and the type of the relational operator is equal sign, calculating possible solutions of the test fields contained in the single expression by using the single expression;
if the number of the test fields is multiple and the type of the relational operator is the equal sign, converting the single expression into a linear matrix, and calculating possible solutions of the test fields contained in the single expression by using the linear matrix;
if the number of the test fields is one and the type of the relational operator is an unequal number, calculating possible solutions of the test fields contained in the single expression by using the single expression and a dynamic programming method;
if the number of the test fields is multiple and the type of the relational operator is the unequal sign, converting the single expression into a nonlinear matrix, and calculating possible solutions of the test fields contained in the single expression by using the nonlinear matrix and the dynamic programming method.
5. The method according to any one of claims 1 to 4, wherein the generating test data corresponding to the scene set by using the feasible domain matrix corresponding to the expression set included in the same scene set includes:
setting the feasible domain matrix corresponding to the expression set contained in the same scene set as a feasible domain matrix to be filtered;
calculating a retention degree for each row of data in the feasible region matrix to be filtered by utilizing a neural network, and judging whether the retention degree is greater than a preset threshold value;
if so, setting the data corresponding to the retention degree as initial test data corresponding to the to-be-filtered feasible domain matrix;
and generating the test data by using the initial test data corresponding to all the processed feasible region matrixes to be filtered.
6. A test data generation apparatus, comprising:
the acquisition module is used for acquiring input data; the input data is directed graph, nodes of the directed graph comprise preset starting nodes and end nodes, and directed edges connecting the nodes are logic expressions comprising test fields;
the scene extraction module is used for extracting a path from the starting node to the ending node from the input data and generating a scene set by using a logic expression on the same path;
the expression splitting module is used for splitting the logic expressions to obtain a single expression and generating an expression set by using the single expression of the same logic expression; the single expression contains the test field, constant values, arithmetic operators and relational operators;
the possible solution calculation module is used for calculating the possible solutions of the test fields corresponding to the single expressions and generating a feasible domain matrix of the expression set by using the possible solutions corresponding to the single expressions contained in the same expression set;
and the test data generation module is used for generating test data corresponding to the scene set by using the feasible domain matrix corresponding to the expression set contained in the same scene set.
7. The test data generation apparatus of claim 6, wherein the scene extraction module comprises:
the initial set extraction submodule is used for generating an initial set for the path by using the logic expression on the same path;
the judgment submodule is used for setting the test fields contained in the initial set as fields to be processed and judging whether the value ranges of the fields to be processed in different logic expressions of the initial set have contradiction;
a removing submodule, configured to remove the initial set and the corresponding path if the initial set and the corresponding path are the same;
and the scene set extraction submodule is used for setting the initial set as the scene set if the initial set is not the scene set.
8. The test data generation apparatus of claim 6, wherein the expression splitting module comprises:
the tree structure transformation module is used for transforming the logic expressions in the scene set into a tree structure according to the priority of the logic operator; the nodes of the tree structure are the single expression or the logical operator;
and the single expression extraction submodule is used for extracting the single expression from the node.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for implementing the test data generation method of any one of claims 1 to 5 when executing the computer program.
10. A storage medium having stored thereon computer-executable instructions which, when loaded and executed by a processor, carry out a test data generation method according to any one of claims 1 to 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210061332.5A CN114385511A (en) | 2022-01-19 | 2022-01-19 | Test data generation method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210061332.5A CN114385511A (en) | 2022-01-19 | 2022-01-19 | Test data generation method and device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114385511A true CN114385511A (en) | 2022-04-22 |
Family
ID=81203171
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210061332.5A Pending CN114385511A (en) | 2022-01-19 | 2022-01-19 | Test data generation method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114385511A (en) |
-
2022
- 2022-01-19 CN CN202210061332.5A patent/CN114385511A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108415830B (en) | Method and device for generating software test case | |
CN109858613B (en) | Compression method and system of deep neural network and terminal equipment | |
CN112328499A (en) | Test data generation method, device, equipment and medium | |
CN111639470B (en) | Simulation test method and system for processor cooperative chip and related components | |
CN109102468B (en) | Image enhancement method and device, terminal equipment and storage medium | |
CN114385511A (en) | Test data generation method and device, electronic equipment and storage medium | |
US10839132B2 (en) | Automatic cover point generation based on register transfer level analysis | |
CN112231459A (en) | Method and system for realizing intelligent question answering of software test based on knowledge graph | |
CN115392048B (en) | Constraint solving engine-based random number generation method with constraint | |
CN116009889A (en) | Deep learning model deployment method and device, electronic equipment and storage medium | |
CN112084667A (en) | Test case generation method and device and electronic equipment | |
CN112783775B (en) | Special character input testing method and device | |
CN112383366B (en) | Frequency spectrum monitoring method and device of digital fluorescence spectrum and storage medium | |
CN111984624B (en) | Method and system for data migration through correction migration model | |
CN114546804A (en) | Information push effect evaluation method and device, electronic equipment and storage medium | |
CN114265780A (en) | Method, system, equipment and storage medium for testing report system | |
CN113766212A (en) | Video decoding function test method, test device and test equipment | |
CN113918355A (en) | Genome assembly method and device, computer readable storage medium and processor | |
CN110716855B (en) | Processor instruction set testing method and device | |
US20240013065A1 (en) | Information processing device, method, and program | |
CN115601198B (en) | Power data simulation method, device, equipment and storage medium | |
CN113658076B (en) | Image restoration method, device, equipment and medium based on feature entanglement modulation | |
CN109086984B (en) | Method and device for evaluating life cycle of platform, computer equipment and storage medium | |
CN113591970A (en) | Training method and device of logistic regression model, electronic equipment and storage medium | |
CN112084734A (en) | Test result processing method and device and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |