CN109918304B - Rapid high-path coverage test case generation method - Google Patents
Rapid high-path coverage test case generation method Download PDFInfo
- Publication number
- CN109918304B CN109918304B CN201910167438.1A CN201910167438A CN109918304B CN 109918304 B CN109918304 B CN 109918304B CN 201910167438 A CN201910167438 A CN 201910167438A CN 109918304 B CN109918304 B CN 109918304B
- Authority
- CN
- China
- Prior art keywords
- branch
- node
- program
- population
- individual
- 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.)
- Active
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 74
- 238000000034 method Methods 0.000 title claims abstract description 73
- 239000011159 matrix material Substances 0.000 claims abstract description 26
- 238000004422 calculation algorithm Methods 0.000 claims abstract description 24
- 230000002068 genetic effect Effects 0.000 claims abstract description 20
- 238000005457 optimization Methods 0.000 claims abstract description 3
- 238000004364 calculation method Methods 0.000 claims description 28
- 230000003044 adaptive effect Effects 0.000 claims description 18
- 230000008859 change Effects 0.000 claims description 3
- 230000035772 mutation Effects 0.000 claims description 3
- 238000012545 processing Methods 0.000 claims description 2
- 238000010586 diagram Methods 0.000 abstract description 5
- 238000011156 evaluation Methods 0.000 description 14
- 238000002474 experimental method Methods 0.000 description 7
- 230000006978 adaptation Effects 0.000 description 6
- 230000006870 function Effects 0.000 description 6
- 230000008569 process Effects 0.000 description 5
- 238000013522 software testing Methods 0.000 description 4
- 238000012217 deletion Methods 0.000 description 3
- 230000037430 deletion Effects 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000013481 data capture Methods 0.000 description 2
- 238000011160 research Methods 0.000 description 2
- 230000009466 transformation Effects 0.000 description 2
- 239000002131 composite material Substances 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000009977 dual effect Effects 0.000 description 1
- 239000002184 metal Substances 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 239000011435 rock Substances 0.000 description 1
- 238000004088 simulation Methods 0.000 description 1
- 230000002123 temporal effect Effects 0.000 description 1
- 238000000844 transformation Methods 0.000 description 1
- 230000001131 transforming effect Effects 0.000 description 1
Images
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention provides a method for generating a rapid high-path coverage test case, which comprises the following steps: acquiring a control flow diagram of a target program, and determining the parent-child relationship in each node in the control flow diagram; judging whether each node is a branch node; obtaining a test case set, taking each test case as an individual in a genetic algorithm, and forming an initial population by a plurality of individuals; constructing a branch crossing matrix; calculating the branch deviation degree of any branch node passing through in the current generation population according to the constructed branch passing matrix; calculating the branch deviation degrees of all branch nodes in the program, and taking the sum of the branch deviation degrees of all branch nodes as the program deviation degree of the individual traversing program in the current generation population; and (3) performing iterative optimization by using a genetic algorithm according to the constructed branch crossing matrix and the program deviation degree, and acquiring the next generation of population and the program deviation degree of the next generation of population crossing the tested program until a test case covering a target path is generated or the maximum evolution algebra of the genetic algorithm is reached.
Description
Technical Field
The invention relates to the field of software testing, in particular to generation of a test case in software testing.
Background
Software testing is an important means for ensuring the quality of software products, and the automatic generation of test data is the key and difficult point of software testing. In recent years, some researchers have developed to generate test data satisfying path coverage criteria by applying evolutionary theory and proposed many new methods for automatically generating test data covering target paths using genetic algorithms. It is well known that the design of fitness functions is a key to genetic algorithms. For example, McMinn (McMinn p. evolution search for test data in the presence of state of behaviour [ D ]. University of Sheffield, England,2005) normalizes the branch distance to [0,1), gives an adaptation value function based on the normalized branch distance and layer proximity, and minimizes the adaptation value function in the course of evolution.zhang, an article of zhang, etc. (zhang, stekeng, route coverage test data evolution generation method based on rare data capture [ J ]. computer science report 2013,36(12), 9-2439) protects rare data crossing difficult-to-cover nodes by capturing the rare data 242, calculates the contribution of an individual to target path test data generation, and combines the contribution with the branch distance and layer proximity to adjust the adaptation value of the individual, which effectively improves the generation efficiency of test data.
However, in the adaptive value calculation of the method, the branch distance is considered, the branch distance calculation needs to be carried out on each simple predicate, h nodes are assumed to be arranged on one target path, at least one simple predicate is arranged in each node, the branch distance calculation needs to calculate h nodes, then summation is carried out, and if each node is a composite predicate, the calculation amount is multiplied; when a flag phenomenon (Binkley D.W., Harman M., Lakhotia K.F. 1ag Remover: a temporal transformation for transforming the loop associated flag [ J ]. ACM transformations on Software Engineering and method, 2009,2(3):110-146.) exists in the program, the adaptation value cannot effectively guide the evolution, thereby becoming a random search; more importantly, when the branch distance corresponding to a predicate of a certain node is large, the branch distance of other nodes is ignored, so that the real effect of an evaluation individual is greatly influenced. In addition, the branch distance, the layer proximity or the individual contribution degree are considered in the adaptive value calculation, so that the algorithm is large in calculation amount and long in time consumption. Therefore, the method cannot realize the generation of the test case with high path coverage rate.
Therefore, in the test data generation, the invention provides the test case generation method which can greatly shorten the generation time of the test case and improve the path coverage rate of the case by counting the true and false branch conditions of the individual crossing branch nodes in the test data evolution generation.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a test case generation method with high speed and high path coverage rate.
Specifically, the invention provides a method for generating a test case with a fast high path coverage rate, which is characterized by comprising the following steps:
the method comprises the following steps of (1) obtaining a control flow graph of a target program, wherein the control flow graph comprises a unique entry node s and an exit node e;
determining parent-child relationships among nodes in the control flow graph based on the control flow graph;
step (3), judging whether each node is a branch node, if not, not processing, and if so, recording the branch node into a computing node;
step (4), obtaining a test case set, taking each test case as an individual, forming a population by a plurality of individuals, and substituting the population into a genetic algorithm;
step (5), calculating the number of individuals of true branches and the number of individuals of false branches of all individuals passing through the calculation node in the population for each calculation node, and respectively constructing branch passing matrixes;
step (6), calculating the branch deviation degree of any branch node passing through in the current generation population according to the constructed branch passing matrix;
step (7), selecting a target path for the tested target program, calculating the branch deviation degrees of all branch nodes in the target path, and taking the sum of the branch deviation degrees of all branch nodes as the program deviation degree of the individual traversing program in the current generation of population;
and (8) performing iterative optimization by using a genetic algorithm according to the constructed branch crossing matrix and the program deviation, adjusting the test case, acquiring the next generation of population and the program deviation of the next generation of population crossing the tested program, and repeating the step until the generated test case covers the target path or reaches the maximum evolution algebra of the genetic algorithm.
Preferably, the method further comprises the steps of calculating an adaptive value of each individual in the current generation population after traversing a target path of the tested program and an adaptive value after deleting a specific individual, determining the probability of the current individual being inherited to the next generation population based on the adaptive value change before and after deleting the specific individual, selecting the next generation initial population based on the probability by the genetic algorithm, and performing intersection and variation by using the initial population to obtain the next generation population of the genetic algorithm.
Preferably, the method further comprises calculating the deviation degree of the tested program before any one of the individuals is deleted and the branch deviation degree of the tested program after any one of the individuals is deleted for the target path.
Preferably, the first and second electrodes are formed of a metal,
calculating a program deviation degree for the target path by the following formula:
wherein,
bbk(t) represents the branch deviation degree of the kth branch node in the tth generation population.
Preferably, the individual x is calculated by the following formulawThe adaptive value of (c):
preferably, the loop node is regarded as a branch node in the step (3).
Technical effects
The test case generation method can greatly shorten the test case generation time and improve the path coverage rate of the case.
Drawings
Fig. 1 is a program source code and a control flow diagram of an example of a program under test employed in embodiment 1 of the present invention.
Fig. 2 is a control flow diagram of an example of a program under test employed in embodiment 1 of the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Basic concept
For ease of introduction, several basic concepts related to the tested procedure are presented.
(1) Control flow graph
The control flow graph is a graphic representation of a control structure of a tested program and is a directed graph G (N, E, s, E), wherein N is called a node set of the graph G and corresponds to a certain statement of the program; e is referred to as the edge set of graph G,i,nodej) The edge, called G, represents the slave sentence nodeiTo statement nodejThe control flow graph of each program also contains a unique entry node s and exit node e, and fig. 2 is the control flow graph corresponding to the triangle classification source program in fig. 1.
In the control flow graph, a node with out degree greater than 1 is called a branch node, and two edges with the branch node as a starting point are true and false branches of the branch node2I.e. branch node, when node2If the predicate (a > ═ b) is true, then the node is executed2True branch b of1When the predicate is false, the node is executed2False branch b of2It should be noted that, according to the Z path coverage, the loop structure can be divided into a dual-branch selection structure according to the number of times the loop body is executed, and the switch statement itself can be expressed as a dual-branch selection structure, so the present invention mainly studies the case where each branch node has two branches.
(2) Single child node
From the control flow graph of the tested program in fig. 2, the parent-child relationships between nodes can be seen. When a certain node has only one child, after the program is run by the test cases, the number of the cases passing through the node is equal to the number of the cases passing through the child, that is, the test cases pass through the parent node and the child in a balanced manner. Therefore, in order to reduce the calculation cost of the method, the single child node is directly abandoned during calculation.
For example, node n in FIG. 11,Only n2A child node, from which it can easily be seen, passes through the node n1And through its child n2Is balanced, so that the parent with a single child will not be considered in calculating the degree of divergenceAnd (4) nodes.
(3) Branch or loop node
Also, according to the control flow graph, each branch node has at least two children, i.e., Next (n) if usedi) Representing a branch node niThe number of children of (n), knowing Next (n)i)>1. It should be noted that, according to the Z path coverage, the loop structure can refer to the article (summer glow, song xin, prince. the test case automatic generation technology research based on the Z path coverage [ J]In 2006(6) 92-94), a dual branch selection structure is formed, so that the loop node is also a branch node, and therefore the branch node and the loop node are collectively referred to as a branch node in the subsequent content of the present invention as a calculation node. The switch statements of branch nodes of more than two children may themselves be represented as a dual-branch selection structure, which in turn converts the target path into a path consisting of single-branch nodes and dual-branch nodes. Since the test cases traversing the branch node may not equally traverse its two children, the number of cases traversing its children is considered to determine the degree of deviation of the test cases traversing its children. Such as n in fig. 22Is a branch node, two children of which are n respectively3And n4At this time, n is statistically crossed3And n4To investigate the number of test cases crossing n2Whether the test case crosses its child n3And n4。
(4) Degree of branch deviation
In order to improve the generation speed of test data, the applicant introduces a new concept, namely branch deviation, and after the data corresponding to all individuals run a program, the difference of the individual numbers of true branches and false branches passing through a certain branch node is the branch deviation of the branch node.
(5) Degree of program deviation
The total deviation degree of the branch nodes on the target path in the program is the program deviation degree, and the value reflects the integral deviation condition of all the individuals passing through all or part of the branches of the tested program.
3 calculation of program deviation
As can be seen from the control flow diagram of fig. 2, the number of use cases traversing a sequential node (single child node) and its immediate successor node is necessarily equal, and therefore, the single child node is not considered in the program deviation calculation in order to reduce the calculation cost. In order to calculate program deviation, firstly, the true and false branch conditions of the individual crossing branch nodes are established, and an individual crossing branch matrix is obtained.
3.1 building Individual traversal Branch matrix
Recording the population scale of the genetic algorithm as m (representing that m test cases exist), wherein the tested program comprises n branch nodes, and counting the branch nodes on the target path for the t generation populationj(j ═ 1,2 …, n) true branch by individual xi(i ═ 1,2 …, m) (each individual represents a test case) crossing, resulting in an individual crossing true branch matrix, denoted cross (t), as follows:
The rows in the matrix represent the individuals x in the population of the t generationiWhether to cross different branch nodes on the target path, and the columns of the matrix represent whether different individuals cross the branch nodes on the target pathj.
In the same way, by counting the branch nodesjFalse branch is individualized xiIn the case of crossing, an individual crossing false branch matrix, denoted cross' (t), may be obtained as follows:
The triangle classification program in fig. 1 is used as the tested program, assuming that the population size m is 4, the target path is selected as"s, 1,2,3,4,5,6,7,8,10,11,12,17, e" when evolving to the 6 th generation, the node of the branch node on the target path in fig. 2 is counted2、node4、node6、node8、node10、node 116 true branches b1~b6And (6) obtaining the true branch matrix cross (6) of the individual crossing under the condition that the individual crossing:
also, by counting the false branches b of 6 branch nodes′ 1~b′ 6And (3) obtaining the individual crossing false branch matrix cross' (6) under the condition of individual crossing:
3.2 calculating program skewness
And when all the individuals correspond to the data and run the program, the deviation degree calculation method of the program comprises the steps of counting the number of the individuals passing through the true and false branches of each branch node according to the individual passing through branch matrixes, calculating the branch deviation degree of each branch node on the target path, and taking the sum of all the branch deviation degrees as the program deviation degree.
3.2.1 calculating Branch skewness
According to the individual crossing true branch matrix cross (t) established in 3.1, calculating the number of individuals crossing the k (k is 1,2 …, n) th branch node true branch in the t generation population, and recording the number as NumkT(t), readily available:
similarly, according to the 3.1 individual crossing false branch matrix cross' (t), the number of the individuals crossing the k-th branch node false branch is obtained and is marked as NumkF(t), then:
from equations (1) and (2), the branch deviation (branch balance) of the kth branch node can be expressed as bbk(t):
From equation (3), the branch deviation defined reflects the degree of equalization that all individuals traversing the kth branch node will actually traverse their true and false branches. Degree of branch deviation bbkThe smaller the value of (t), the better.
3.2.2 calculating program skewness
According to the formula (3), the branch deviation degrees of all branch nodes in the program are calculated, the sum of the branch deviation degrees of all branch nodes is taken as the program deviation degree (program balance) of the individual traversing program in the t-th generation population, and is recorded as pb (t), as shown in the formula (4).
The triangle classification procedure in fig. 1 is still used as an example. According to the 6 th generation individual crossing true branch matrix cross (6) and the individual number calculation formula (detailed formula (1)) of the true branch crossing branch node, the first column of the matrix cross (6) is summed to obtain the crossing first branch node2Number of individuals in true BranchAccording to the 6 th generation individual crossing false branch matrix cross '(6) and the individual number calculation formula (detailed formula (2)) crossing the false branches of the branch nodes, the first column of the matrix cross' (6) is summed to obtain the crossing first branch node2False branchNumber of individuals ofBy analogy, the branch node passing through the triangle classification program can be obtained4、node6、node8、node10、node11The number of true and false branches, as shown in Table 1, is further calculated according to the formula (3) to obtain the 1 st branch node2B degree of branch deviation of1(6)=|Num1T(6)-Num1F(6)|/(Num1T(6)+Num1F(6) |3-1|/(3+1) ═ 0.5, and the branch deviation degrees of other branch nodes were calculated in the same manner as shown in table 1.
TABLE 1 calculation of Branch deviation
Finally, according to the program deviation degree calculation method (see the formula (4)) the program deviation degree is obtained:
4. test case evolution generation
In order to obtain whether a certain individual can improve the program testing process, the method comprises the steps of deleting the certain individual, recalculating the branch deviation degree of the kth branch node and the program deviation degree of the tested program, and calculating the influence of the individual on the program path coverage rate according to the change condition of the program deviation degree before and after deleting the individual.
4.1 calculation of program skewness after deletion of individuals
According to the calculation formula (detailed formula (1)) of the individual crossing true branch matrix cross (t) in 3.1 and the individual number of the crossing branch node true branches in 3.2, the individual x is deletedw(w is more than or equal to 1 and less than or equal to m) and number Num 'of individuals passing through true branch of kth branch node'kT(xwAnd t) is expressed as:
as shown in formula (5), if the w-th row of the matrix cross (t) is deleted, the number of the individuals of the true branch passing through the k-th branch node is recalculated to obtain Num'kT(xwT), that is to say Num'kT(xwT) calculation without taking into account the individual xwA true branch case crossing the kth branch node.
Similarly, the individual x is deleted according to the formula (see formula (2)) calculated by the individual crossing false branch matrix cross' (t) in 3.1 and the individual number of crossing branch node false branches in 3.2wThen, the number Num 'of false branch units passing through the kth branch node'kF(xwAnd t) is expressed as:
further according to the formula (5) and the formula (6), the individual x is deletedwBranch deviation bb 'of the kth-after branch node'k(xwAnd t) is expressed as:
thereby calculating a deleted individual xwProgram deviation degree of the kth branch node, denoted as pb' (x)wT), then pb' (x)wT) can be expressed as:
4.2 calculation of Individual fitness values
Generally, genetic algorithms will inherit the higher fitness individuals of the current population into the next generation population according to some rule, that is, the higher fitness individuals will be relatively largeIn the process of calculating the individual adaptive value, program deviation obtained after running a program according to the data corresponding to the individuals in the population of the t generation and the deleted individual x need to be consideredwObtaining the size relationship between the program deviation degrees to obtain the influence of the individuals on the program deviation degrees, namely the individuals xwAdapted value of f (x)wT), can be expressed as:
as can be seen from equation (9), the present invention considers deleting the individual x when calculating the individual adaptive valuewVariation of degree of program deviation before and after, if individual xwThe deletion of (b) increases the program skew, namely pb' (x)wT) > pb (t) indicating the individual xwCan effectively reduce the deviation degree, then the individual x is improved in the evolution processwPreferably, if there are a plurality of individuals capable of reducing the degree of deviation, equation (9) ensures that the greater the degree of deviation reduction of the individual from the program, the higher the individual's fitness valuewIs removed so that the program deviation degree is unchanged or reduced, namely pb' (x)wT is less than or equal to pb (t), which indicates that the individual xwThe degree of deviation cannot be reduced, and such individuals are eliminated by reducing the number of individuals xwThe adaptation value of (a) is set to 0;
based on the calculation formulas (see formulas (1) and (2)) for the number of individuals crossing the true and false branch matrixes cross (t) and cross' (t) in 3.1 and the true and false branches crossing the branch nodes in 3.2, the process proceeds to generation 6, and when the individual x is deleted1Then deleting the value of the 1 st row in the cross (6) matrix, and summing the rest elements in the first column in the cross (6) matrix to obtain a deleted individual x1Backward traversing first branch node2Number of individuals in true Branch Similarly, obtaining the number of individuals of the true branch passing through other branch nodes; in the same way, based on cross' (6), the result isThe number of individuals passing through the true and false branches of other branch nodes is calculated in the same way, and the deleted individual x is calculated1Last first branch node2Degree of branch deviation of Similarly, the branch deviation of other nodes is calculated, the number of true and false branches crossing the branch node and the branch deviation are shown in Table 2. according to Table 2, the deleted individual x is further calculated1Degree of program deviation afterIn the same way, the program bias for deleting other individuals pb' (x) can be calculated2,6)≈2.33,pb′(x3,6)≈2.33,pb′(x4,6)≈3.67.
Table 2 deletion of individuals x1Calculation of rear Branch deviation
Program bias pb (6) ≈ 3.33 based on pre-deleted individuals in 3, and deleted individuals x1Post program deviation pb' (x)16) approximately equal to 3.99 due to pb' (x)16) > pb (6), calculating the individual x from the formula (9)1Adapted value of f (x)1,6)=pb′(x16) -pb (6) ≈ 0.66, with the same reasoning, yielding f (x)i,6)≈0(i=2,3),f(x46) ≈ 0.32. according to f (x)1,6)>f(xi6) (i ═ 2,3,4), illustrate individual x1The original deviation degree can be reduced to the maximum extent; and f (x)16) and f (x)4And 6) are all greater than 0, indicating that the individual x1With the individual x4Both can effectively reduce the degree of deviation covered by the program, and the two individuals have a greater probability to be preserved in the evolution; individual x2With the individual x3The adaptive value of 0 is eliminated in the evolution process, and the method provided by the invention can effectively distinguish the influence of different individuals on the program deviation.
4.3 test case evolution Generation step
(1) Determining a target path of a tested program, inserting the tested program, assigning control parameters of a genetic algorithm, and setting the experiment times, the maximum evolution algebra of each experiment, cross operators, mutation operators, population scale and test case range;
(2) obtaining a test case set, taking each test case as an individual, forming a population by a plurality of individuals, and substituting the population into a genetic algorithm;
(3) respectively taking each evolved individual as input data to run a tested program;
(4) judging whether an individual crossing path is completely the same as the target path or the algorithm reaches a preset maximum evolution algebra, if so, stopping the population evolution, and turning to the step 7;
(5) calculating an adaptive value of the evolved individual;
(6) sequentially carrying out selection, crossing and mutation operations on the population to generate a progeny population, and turning to the step 3;
(7) stopping the evolution process of the population, storing the evolved individuals, and outputting the test cases passing through the target path.
5. Experiment of
Although some test case generation methods exist in the prior art, the methods in the prior art can not achieve the effect of the invention.
For example, the following documents show some methods, and the present invention adopts similar procedures to compare the prior methods with the present invention in detail.
[1]McMinn P.Evolutionary search for test data in the presence of state behaviour[D].University of Sheffield,England,2005
[2] Zhang rock, Gundon Wei, Path covering test data evolution generation method based on rare data capture [ J ] computer science report 2013,36(12), 2429-2439
[3] Xiahui, Song Xin, King, research on test case automatic generation technology based on Z path coverage [ J ] modern electronic technology 2006(6):92-94
In order to verify the effectiveness of the method, 1 benchmark program and 5 industrial cases are selected for a tested program, wherein the benchmark program and the 5 industrial cases are C language programs, and the simulation environment is VC + +6.0. in order to verify the performance of the method, each group of experimental results is compared and analyzed with the results of the similar method, and the selected comparison method comprises the steps of adopting the combination of the branch distance and the layer proximity as an adaptive value function in the method of the document [1 ]; the method described in the document [2] protects the rare data crossing nodes which are difficult to cover by capturing the rare data, and calculates the contribution of the individual to the generation of the target path test case, in the method, the calculation of the adaptive value function increases the individual contribution on the basis of the combination of the original branch distance and the layer proximity, and the document [1] adopts the genetic algorithm to evolve and generate the test case, and compares the test case with the test case to verify the efficiency of the method for generating the test case Average run time and success rate.
5.1 benchmark program experiment
In order to ensure that the experimental conditions are basically the same, 15 times, the equilateral triangle path with high difficulty is selected as the target path, "s, 1,2,3,4,5,6,7,8,10,11,12,17, e", the experimental setting comprises six conditions, different data ranges, population scales and maximum termination algebra are selected for different conditions, the experimental setting and results are listed in table 3, the smaller the average evaluation times is, the better the performance of the description algorithm is, and the success rate refers to the ratio of the experimental times for successfully generating test cases within the maximum operation algebra to the total experimental number (namely 15 times).
TABLE 3 triangle classification procedure experimental results
From table 3 it can be seen that:
(1) from the evaluation times, when the data range is smaller than [1,128], the average evaluation time of the document [2] is 2130.0, the invention is 1993.3 and is about 1.1 times of the invention, the average evaluation time of the document [1] is 54443.33 and is about 27.3 times of the invention, when the data range is larger than [1,1024], the average evaluation time of the document [2] is about 8.1 times of the invention, and the average evaluation time of the document [1] is about 161.5 times of the invention.
(2) From a runtime perspective, the method of the present invention requires less runtime for different data ranges than the other two methods, and this trend is more pronounced as the data range is increased, such as when the data range is at 1,4096, the average operating time of document [2] is 0.5619s, the present invention is 0.0787s, which is about 7 times as long as the present invention, the average operating time of document [1] is 21.2714s, which is about 270 times as long as the present invention, this is sufficient to illustrate that the time for generating test cases is significantly shorter for the method of the present invention than for the other two methods, since document [1] when calculating the adaptation values, the layer proximity and the branch distance are considered, the individual contribution degree is increased in the document [2] on the basis of the document [1], and the method only needs to calculate the true and false branch situation of the individual crossing program to obtain the influence of the individual on the program deviation degree, so that the running time of the algorithm is shorter.
(3) From the success rate, under the conditions of different data ranges, population scales and maximum evolution generations, the success rate of the method can reach 100 percent, which fully shows the effectiveness of the method for generating the test cases.
5.2 Industrial example experiments
In order to verify the effectiveness of the method provided by the invention on the industrial examples, five industrial examples are selected for carrying out an experiment, each program randomly selects a feasible path as a target path, the program description and other parameter settings (see the prior art 23) are listed in table 4, wherein the node number represents the node number of the selected target path, each method is set to independently run for 50 times in the experiment, and the average value of the evaluation times, the average value of the running time and the success rate of generating the test examples are analyzed, and the experimental results are shown in table 5.
Table 4 industrial use case parameter settings
As can be seen from Table 5, in the evaluation times, the average evaluation times of the method of the present invention are less than those of the similar methods in the industrial use case experiment; for example, for more complex industrial case Flex, the evaluation times of the method of the present invention are 1965700.4, the evaluation times of document [4] are 6967436.7, and the evaluation times of document [1] are 13747252.2, and the evaluation times of the method of the present invention are less than those of the similar method, because under the condition of a certain population scale, the method of the present invention needs fewer running algebras to evolve and generate the test case satisfying the target path; the time taken by the method of the invention is significantly less than that of the methods proposed in documents [1] and [2] for all selected industrial examples, as seen from the average value of the run times, for example, for complex use cases Flex, the run time of the method of the invention is 97.3572s, the method in document [2] is 169.3522, 71.995s more than that of the invention, the average value of the run time of document [1] is 354.8913, and the run time of the invention is 257.5341s more than that of the invention; for example, for all cases, the method can generate test cases meeting the target path, the reference program and the industrial case Replace, Sed and Flex programs, the method can generate the test cases of the target path with the success rate of 100% and the method in the document [1] has the success rates of 63%, 50% and 38% respectively, and the experimental results fully verify the effectiveness of the method in generating the test cases of the target path and can improve the generation efficiency of the test cases.
TABLE 5 Experimental results of Industrial example
In summary, the invention provides a rapid test case evolution generation method with high path coverage. After the tested program is operated by the data corresponding to the individuals in the population, the number of test cases passing through each branch in the program is counted, and an adaptive value function related to the influence degree of the individuals in the population on the program deviation degree is designed according to the number of the test cases, so that the individuals with small influence on the program deviation degree are ensured to have a better adaptive value, and the generation efficiency of the test cases is effectively improved. The experimental result shows that compared with the similar method, the method has high success rate of generating the test case and consumes less time.
Claims (5)
1. A method for generating a fast high-path coverage test case is characterized by comprising the following steps:
the method comprises the following steps of (1) obtaining a control flow graph of a target program, wherein the control flow graph comprises a unique entry node s and an exit node e;
determining parent-child relationships among nodes in the control flow graph based on the control flow graph;
step (3), judging whether each node is a branch node, if not, not processing, and if so, recording the branch node into a computing node;
step (4), obtaining a test case set, taking each test case as an individual, forming a population by a plurality of individuals, and substituting the population into a genetic algorithm;
step (5), calculating the number of individuals of true branches and the number of individuals of false branches of all individuals passing through the calculation node in the population for each calculation node, and respectively constructing branch passing matrixes;
step (6), calculating the branch deviation degree of any branch node passing through in the current generation population according to the constructed branch passing matrix;
step (7), selecting a target path for the tested target program, calculating the branch deviation degrees of all branch nodes in the target path, and taking the sum of the branch deviation degrees of all branch nodes as the program deviation degree of the individual traversing program in the current generation of population;
step (8), iterative optimization is carried out according to the constructed branch crossing matrix and the program deviation degree by utilizing a genetic algorithm, a test case is adjusted, the next generation of population and the program deviation degree of the next generation of population crossing the tested program are obtained, the step is repeated until the generated test case covers the target path or reaches the maximum evolution algebra of the genetic algorithm,
calculating a program deviation degree for the target path by the following formula:
wherein bbk(t) represents the branch deviation degree of the kth branch node in the tth generation population, NumkT(t) represents the number of individuals in the population of the t generation who pass through the true branch of the kth (k is 1,2 …, n) branch node, NumkF(t) represents the individual number of false branches for the kth branch node.
2. The method for generating the test case with the fast high path coverage according to claim 1, further comprising calculating an adaptive value of each individual in the current generation population passing through a target path of the tested program and an adaptive value after deleting a specific individual, determining a probability that the current individual is inherited to the next generation population based on the adaptive value change before and after deleting the specific individual, selecting the next generation population based on the probability by the genetic algorithm, and performing crossover and mutation by using the population to obtain the next generation initial population of the genetic algorithm.
3. The method according to claim 2, further comprising calculating, for the target path, the branch deviation of the tested program before deleting any one of the individuals and the branch deviation of the tested program after deleting any one of the individuals.
5. the method according to claim 1, wherein the loop node is regarded as a branch node in the step (3).
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910167438.1A CN109918304B (en) | 2019-03-06 | 2019-03-06 | Rapid high-path coverage test case generation method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910167438.1A CN109918304B (en) | 2019-03-06 | 2019-03-06 | Rapid high-path coverage test case generation method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109918304A CN109918304A (en) | 2019-06-21 |
CN109918304B true CN109918304B (en) | 2022-04-12 |
Family
ID=66963500
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910167438.1A Active CN109918304B (en) | 2019-03-06 | 2019-03-06 | Rapid high-path coverage test case generation method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109918304B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111309608B (en) * | 2020-02-13 | 2023-09-05 | 咪咕音乐有限公司 | Test case selection method and device, electronic equipment and readable storage medium |
CN115576848B (en) * | 2022-11-10 | 2023-04-07 | 江西财经大学 | Multi-path coverage test method combining key edge probability and path layer proximity |
CN116010291A (en) * | 2023-03-28 | 2023-04-25 | 江西财经大学 | Multipath coverage test method based on equalization optimization theory and gray prediction model |
CN116775499A (en) * | 2023-08-21 | 2023-09-19 | 中国电信股份有限公司 | Test data generation method, device, computer equipment and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2003289969A (en) * | 2002-04-02 | 2003-10-14 | Mitsuo Kawaguchi | Knob |
CN102323906A (en) * | 2011-09-08 | 2012-01-18 | 哈尔滨工程大学 | MC/DC test data automatic generation method based on genetic algorithm |
CN103593287A (en) * | 2013-10-30 | 2014-02-19 | 北京信息控制研究所 | Genetic-algorithm-based method for automatically generating data stream test cases |
-
2019
- 2019-03-06 CN CN201910167438.1A patent/CN109918304B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2003289969A (en) * | 2002-04-02 | 2003-10-14 | Mitsuo Kawaguchi | Knob |
CN102323906A (en) * | 2011-09-08 | 2012-01-18 | 哈尔滨工程大学 | MC/DC test data automatic generation method based on genetic algorithm |
CN103593287A (en) * | 2013-10-30 | 2014-02-19 | 北京信息控制研究所 | Genetic-algorithm-based method for automatically generating data stream test cases |
Non-Patent Citations (2)
Title |
---|
一种基于改进遗传算法的面向路径测试;刘双悦等;《计算机应用 自动化技术与应用》;20100325;第29卷(第3期);第36-38页 * |
基于面向路径的遗传算法的测试用例自动生成;金虎等;《计算机工程》;20070228;第33卷(第3期);第21-23页 * |
Also Published As
Publication number | Publication date |
---|---|
CN109918304A (en) | 2019-06-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109918304B (en) | Rapid high-path coverage test case generation method | |
Yi et al. | Behavior of crossover operators in NSGA-III for large-scale optimization problems | |
US11610131B2 (en) | Ensembling of neural network models | |
US20210287097A1 (en) | Execution of a genetic algorithm having variable epoch size with selective execution of a training algorithm | |
US8489526B2 (en) | Controlling quarantining and biasing in cataclysms for optimization simulations | |
Brunet et al. | Noisy traveling waves: effect of selection on genealogies | |
Vistro et al. | The cricket winner prediction with application of machine learning and data analytics | |
Shao et al. | An efficient discrete invasive weed optimization for blocking flow-shop scheduling problem | |
CN109325691A (en) | Abnormal behaviour analysis method, electronic equipment and computer program product | |
CN111242310B (en) | Feature validity evaluation method and device, electronic equipment and storage medium | |
US20060230018A1 (en) | Mahalanobis distance genetic algorithm (MDGA) method and system | |
CN112699045A (en) | Software test case generation method based on multi-population genetic algorithm | |
WO2009017640A2 (en) | Process modeling and optimization method and system | |
Elsayed et al. | Integrated strategies differential evolution algorithm with a local search for constrained optimization | |
CN109284766A (en) | A kind of feature selection approach of Multivariate Discrete, device, equipment and storage medium | |
Sun et al. | Biochemical systems identification by a random drift particle swarm optimization approach | |
Yamany et al. | Attribute reduction approach based on modified flower pollination algorithm | |
CN112346997B (en) | Automatic test case generation method and terminal | |
Al-Helali et al. | Genetic Programming for Feature Selection Based on Feature Removal Impact in High-Dimensional Symbolic Regression | |
Chattopadhyay et al. | Feature selection using differential evolution with binary mutation scheme | |
Zhuang et al. | Improving Monte-Carlo tree search for dots-and-boxes with a novel board representation and artificial neural networks | |
US7272584B2 (en) | Use of dominance to improve performance or increase search space in genetic algorithms | |
Becheler et al. | Genetic signatures of a range expansion in natura: when clones play leapfrog | |
Merelo et al. | There is noisy lunch: A study of noise in evolutionary optimization problems | |
Xie | Time series prediction based on recurrent LS-SVM with mixed kernel |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |