CN107590073B - Automatic test case generation method based on path coverage software test - Google Patents

Automatic test case generation method based on path coverage software test Download PDF

Info

Publication number
CN107590073B
CN107590073B CN201710766422.3A CN201710766422A CN107590073B CN 107590073 B CN107590073 B CN 107590073B CN 201710766422 A CN201710766422 A CN 201710766422A CN 107590073 B CN107590073 B CN 107590073B
Authority
CN
China
Prior art keywords
test
test case
path
program
value
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
Application number
CN201710766422.3A
Other languages
Chinese (zh)
Other versions
CN107590073A (en
Inventor
黄翰
刘方青
颜学明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Microscience Intelligent Inspection Foshan Technology Co ltd
Original Assignee
South China University of Technology SCUT
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by South China University of Technology SCUT filed Critical South China University of Technology SCUT
Priority to CN201710766422.3A priority Critical patent/CN107590073B/en
Publication of CN107590073A publication Critical patent/CN107590073A/en
Application granted granted Critical
Publication of CN107590073B publication Critical patent/CN107590073B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention provides a test case automatic generation method based on path overlay software test, which comprises the steps of firstly analyzing codes of a tested program, then obtaining a Control Flow Graph (CFG) of the program and paths existing in the program, then obtaining an adaptive value function for calculating a group of test cases according to the control flow graph obtained in the last step and a set method based on branch distance, then carrying out iterative update on a randomly initialized population through a differential evolution algorithm and a convergence speed controller, then recording a first test case covering the path corresponding to the program, stopping until all the test cases of the paths are obtained or the iteration times of the algorithm exceed a limit, and outputting a test case set covering the path corresponding to the program. The method can effectively utilize heuristic information of the tested program based on the path coverage test case, and can be applied to the actual software test working environment.

Description

Automatic test case generation method based on path coverage software test
Technical Field
The invention relates to the field of software testing of computer software engineering, in particular to an automatic generation method for generating a software test case based on path coverage.
Background
With the vigorous development of society and the continuous improvement of IT technical level, software products are more and more popularized in our lives and play irreplaceable roles. The quality of software products becomes the focus of increasing attention of people, and the production of a software product with guaranteed quality is one of the important targets of manufacturers and is also an important weight for enterprises to cope with market competition. Software testing is one of the important processes for software hit to ensure the quality of software products. Software testing costs at least 50% of the cost of software development. Software testing has two modes of manual testing and automatic testing, the automatic testing is not really popularized in real life, and most of the testing is mainly manual testing. However, the development degree of the technology determines the complexity degree of the software, the difficulty and the workload of the test are increased, the energy of people is limited, and the situation is urgently to be changed; in addition, a large amount of work which is low in technical content and is frequently repeated exists in the software test, and the labor consumption can be greatly reduced if a machine is used for completing the work; testing software in an automated fashion is therefore the best solution to the current problem. An outstanding automatic test scheme can practice thrift a large amount of manpower, material resources and financial resources, reduces the resource consumption, improves the performance of enterprises simultaneously.
To obtain software with zero defect quality, an infinite number of test cases need to be generated to measure it. It is not feasible to exhaust the inputs of a program in the real world, regardless of the size of the program, so it is desirable to find an optimal way to reduce the consumption of resources (e.g., time, cost, human resources, system components, etc.) during the testing process without compromising the quality. The goal of the optimization is to generate test cases that cover the available test cases in the tested system with as little time and cost as possible.
Most of the dynamic methods used in the existing methods are based on statement coverage or branch coverage, and among all coverage types tested by software, path coverage is the strongest coverage, so that the method has stronger error correction capability and can more effectively detect flaws and errors of the software. The software coverage criterion based on path coverage adopted in the invention uses a differential evolution algorithm and a self-adaptive value function. The differential evolution algorithm has strong capability, and the automatic generation of the test case based on the path coverage is a search problem with high difficulty, and the problem is very suitable for using the differential evolution algorithm. On the other hand, most of the static methods used in the existing methods are executed by using symbols to generate test cases, and the method is too complex to be calculated for a test program with a multi-branch structure. The invention adopts a reasonable self-adaptive value function which helps the differential evolution algorithm to search and combine the covered and uncovered path information to obtain the test case set covering the test program path, and the efficiency is very high.
Disclosure of Invention
Aiming at the defects of the existing software test case generation software system, the invention provides a software test case automatic generation method based on path coverage. The invention aims to design a reasonable automatic test case generation method based on path coverage, which helps software testers to quickly obtain test cases covering all paths of a tested program, so that BUG possibly existing in the test program can be better detected by using the test cases and is used for repairing program BUGs.
The method for automatically generating the test case based on the path coverage software test comprises the following steps:
(a) analyzing the tested program to obtain a Control Flow Graph (CFG) of the program, and coding the existing path;
(b) determining the code of the tested program according to the test problem;
(c) obtaining an adaptive value function for calculating an adaptive value of a test case by inputting a problem code determined according to a specific test problem in the step (a) and the Control Flow Graph (CFG) obtained in the step (b) and a preset method for calculating a branch distance;
(d) randomly initializing a population in a uniformly distributed mode within the value range of the test case;
(e) updating the iterative population by using a differential evolution algorithm (DE), a convergence rate controller (CSC) aiming at the test case generation problem and the adaptive value function obtained in the step (c) according to the population obtained in the step (d);
(f) recording the test cases covering the current uncovered paths of the tested programs in the population individuals in the step (d) and the step (e);
(g) detecting whether an iteration termination condition of a differential evolution algorithm is met: if the condition is not met, jumping back to the step (e) to continue execution; and if the condition is met, outputting the recorded test case set covering the corresponding path.
In the method for automatically generating the test case based on the path coverage software test, the input, output, judgment and circulation branches are analyzed in the step (a), and the Control Flow Graph (CFG) of the tested functional unit is drawn by taking the information as the reference. After the control flow graph is obtained, the number of independent paths existing in the tested program is obtained according to the circle complexity of the control flow graph, wherein the calculation formula is as follows: and v (g) ═ e-n +2p, where e denotes the number of edges in the control flow graph, n denotes the number of nodes in the control flow graph, and p denotes the number of connected components in the graph, and since the control flow graphs are all connected, p ═ 1, and in the following steps, all independent paths can be found out according to the control flow graph and the path number information. Coding all paths needing to be covered according to the number of the paths, numbering 1-N all judgment and circulation branches, then representing one path by an N-bit character string, wherein the k-th bit is '1' to represent that the ith node moves in the No direction, and '0' to represent that the ith node moves in the Yes direction, for the branches of a case statement, more than 2 branches are possible, the corresponding values of the branches are '0', '1', …'m-1' (m is the number of the branches of the case), and if the path does not pass through the jth branch, the value of the jth bit of the path can be set as the character 'N'.
In step (b) of the method for automatically generating a test case based on a path coverage software test, the specific code of the program to be tested is determined, and the type and range of input and output data of the program to be tested need to be analyzed, and the specific processing includes: for a variable of a numerical type, firstly, whether the variable is an integer or a floating point number needs to be determined, and a value range of the variable is set; if the variable is a character type, an ASCII code symbol is represented by using integers in a range of [0,255], and a corresponding character string with the length of m can be represented by using m integers in a range of [0,255 ]; if the variable is an enumeration type, where the number of enumeration choices is k, we use the integer in [1, k ] to represent an incoming test case. For the case that the input and the output are the combination of the types, only the types of the input and the output need to be combined to obtain a test case. In summary, for different types of variables, we are defaults to converting the problem into a more tractable numerical search problem, the encoding fitting the search of the differential evolution algorithm that will be used later.
In the step (c) of the test case automatic generation method based on the path coverage software test, the calculation adaptation is carried outThe calculation method of the value function benchmark function () is that which nodes of the Control Flow Graph (CFG) generated in the step (a) the input test case X passes through are determined, and the formed path is called PXThe test case is on the path PXThe branch distance evaluation value of the upper j-th branch node is denoted as f (P)XJ) at f (P)XJ) ensures the effect of the fitness function using two strategies, the first being f (P) for covered path branchesXJ) the value will be set to 0 and the second strategy is for uncovered paths PXJ (th) node of (2)
Figure BDA0001394197290000031
Figure BDA0001394197290000032
Where epsilon is a constant with a small value, to prevent the denominator from being zero, we set here to 0.001,
Figure BDA0001394197290000033
then it represents that test case X is at the node
Figure BDA0001394197290000034
The calculation rule of the score distance is shown in table 1. By calculating the path P of the test case XXF (P) of each branch node of (1)XAnd j) after the value, accumulating to obtain an adaptive value of the test case X:
Figure BDA0001394197290000035
(where k represents the number of branches passed by test case X).
Figure BDA0001394197290000036
Figure BDA0001394197290000041
TABLE 1 test case cost function calculation rules at branch
K is a constant, we set the value to 10
The strategy one and the strategy two ensure that the tested program can ensure that the adaptive value of the test case covering the covered path is very small, and the adaptive value of the test case successfully covering the uncovered path is very large, so that the algorithm is better helped to obtain a target test case set.
In the step (d) of the test case automatic generation method based on the path coverage software test, a proper input range [ lb, ub ] is selected according to different input values of the test program, wherein lb is a lower value range and ub is an upper value range, then a population is randomly initialized in the ranges by using a uniform distribution mode, the method is based on the condition that a tester does not fully know the tested program, and the distribution of the test cases can be uniform by using the uniform random distribution mode in the value range of the variable, so that the algorithm is helped to search an unknown whole search space. In an actual application scenario, if a tester knows a tested program, some good initial input values can be initialized manually, so that the algorithm can find test cases covering all paths of a test problem more quickly according to the good initial solutions.
In the step (e) of the test case automatic generation method based on the path coverage software test, a differential evolution algorithm (DE) and a convergence rate controller (CSC) are selected to iterate a population, according to an experimental result of the inventor, the efficiency of the algorithm is relatively highest when the population size is 50, and an iterative formula of the differential evolution algorithm is as follows: v. ofi=yi+F*(yj-yk) Wherein v isiIs the new test sample obtained, and yiIs the old test case before differential evolution, yjAnd ykAre two test cases randomly chosen from all solutions. After the above calculation is completed, the cross operation of the DE algorithm is performed:
Figure BDA0001394197290000042
first, for the jth dimension of the ith generation of the test case X, a [0,1 ] is generated]Random number in between
Figure BDA0001394197290000043
Then, if
Figure BDA0001394197290000044
Is less than the preset cross probability PcThen the previous solution is retained; if it is not
Figure BDA0001394197290000045
Is greater than the preset cross probability PcThe solution just found is discarded and the previous solution is retained. We will cross the probability PcThe value of (2) is preset to be 0.1, and the operation mainly ensures that the previous generation population has certain probability to retain information and protects the diversity of the algorithm.
In the step (e), a speed reduction operator of the convergence rate controller (CSC) adds a region hit number statistical data structure, and divides the range of the program input variable before the program runs each time, specifically: the value range of the ith dimension of the test case X is [1,100], the test case X is averagely divided into 10 regions, the hitting times of each region are counted, and the region with the minimum hitting times of each dimension of the test case is selected and initialized when the speed reduction operation of a convergence rate controller (CSC) is carried out each time.
The convergence rate controller (CSC) of the present invention operates as follows: firstly, a matrix C is defined, the matrix C has n rows and m columns, the (i, j) th element of the matrix C represents the influence of the ith dimension of the input parameter on the jth branch judgment node of the test program, the matrix C is updated when a group of test cases are generated each time, the trend of a certain judgment node is changed by comparing the change of different dimension values, and if the change occurs, the corresponding value is increased by one. After updating the matrix, analyzing whether the DE algorithm is trapped in a local optimal value or not through iterative updating of the DE algorithm of 10 generations each time, and if the DE algorithm is trapped in the local optimal value, re-initializing the population through uniform distribution in a [ lb, ub ] range in the similar step (d); if the local optimum is not trapped, finding a node which is not covered by the current test case from the uncovered path, finding the input data dimension influencing the node, finding the optimized dimension by a roulette mode according to the influence value in the matrix C, and carrying out dynamic step search.
In the step (f) of the automatic test case generation method based on the path coverage software test, the initial solution generated in the step (d) and the solution iteratively generated by the differential evolution algorithm (DE) in the step (e) are analyzed, the path of the test case coverage covered by the test program corresponding to the solutions is judged, and if the test case covers a path which is not covered before, the test case is recorded. Thus, after the iteration of the algorithm is finished, a set of test cases is obtained
Figure BDA0001394197290000051
(where k represents the number of paths owned by the program under test), each test XiAnd (i ═ 1,2, and k) covers a path different from other test cases in the set, namely, the path coverage of the whole tested program is completed.
In the step (f), recording an initial solution and a test case covering a path which is not covered currently in a tested program in the test case generated by iteration of a differential evolution algorithm (DE); for the specific test condition, if the tester needs to cover the condition of a plurality of test cases of the same path, the parameters can be adjusted, and more test cases covering the same path are recorded; for the case where only the first test case of the overlay path is recorded, the mathematical model is as follows: x ═ X1,x2,...,xNRepresents all test cases found, each xiMay be an integer vector, i 1,2, N, with P being the program under test1,p2,...,pLL paths, j 1,2, L, and we are based on the path overlay software test case generation problem:
the target is as follows: minimization of m
And (3) constraint:
Figure BDA0001394197290000052
Figure BDA0001394197290000061
Figure BDA0001394197290000062
Figure BDA0001394197290000063
j=1,2,...,L;1≤n1<n2<...<nm≤N。
in the method for automatically generating the test cases based on the path coverage software test, the iteration termination conditions of the differential evolution algorithm (DE) in the step (g) are two, the first is that the algorithm obtains all the test cases covering the paths of the test program, the other is that the algorithm does not obtain the test cases covering all the paths of the test program after multiple iteration updates, and in the setting, the maximum iteration test is set to be Max 108. If the iteration termination condition is not met, the algorithm does not find a target solution set, so that iteration search needs to be continued; when the iteration termination condition is met, one condition is that a target solution set is found, and the other condition is that the iteration times are used up, and a result is not obtained after the iteration is generally performed for Max times, the complexity of the tested program should be extremely high, or the value range of the variable is too large, and the range should be reduced for operation. After the execution is finished, the algorithm outputs the recorded test case set covering the corresponding path.
The invention provides a test case automatic generation method based on path coverage software test, firstly analyzing the judgment and the circular branch of a tested program to obtain a program Control Flow Graph (CFG), then determining the code of a problem according to the actual input and output data type and range of the tested problem, then obtaining an adaptive value function BenchMark function () for calculating the adaptive value of the test case according to the CFG graph, the problem code and the set branch distance calculation method, then randomly initializing a population in a uniformly distributed mode in the value range of the test case, then iteratively updating the initialized population by using a differential evolution algorithm (DE) and a designed convergence rate controller (CSC) and BenchMark function (), recording the test case covering the uncovered path of the program in the processes of initializing and iterating the differential evolution algorithm, and finally judging whether the DE algorithm completes iteration, and if the iteration ending condition is not met, continuing to execute the DE algorithm, if the iteration ending condition is met, ending the DE algorithm iteration, and outputting the recorded test case set covering the corresponding path.
Compared with the prior art, the invention has the following advantages and technical effects:
for software automatically generated by software testing, most of the software on the market uses simple random rules or a static symbolic execution mode, the former is too simple, and the latter has weak capability of solving complex testing problems. Secondly, methods for generating dynamic software test cases all need specific coverage criteria, most of the existing methods generate test cases by adopting methods based on statement coverage or branch coverage, path coverage is used as a stronger coverage criterion, and the corresponding test cases found based on the path coverage criterion have stronger error correction capability. The invention adopts a differential evolution algorithm (DE) and a designed convergence rate controller (CSC) to search feasible solutions and designs a corresponding adaptive test case adaptive value calculation function, so that software testers only need to analyze branches of a test program according to simple rules, design a corresponding adaptive value calculation function benchmark function () and determine codes of problems according to input and output required by the test program, and the method can be used for automatically generating the test cases based on path coverage of the test problems by using a computer. The method is relatively convenient, does not need testers to deeply know the logic and other rules of the tested program, has strong usability, and has wide application space as long as the testers perform simple operation according to the method.
Drawings
Fig. 1 is a method for automatically generating a test case based on a path overlay software test in an implementation method.
FIG. 2 is an example test program "Triangle" code in an embodiment.
FIG. 3 is an exemplary test program "Triangle" control flow graph in an embodiment.
Detailed Description
Embodiments of the present invention are further described below with reference to examples, but the implementation of the present invention is not limited thereto, and it should be noted that, unless specifically described in detail below, all of the following can be understood or implemented by those skilled in the art with reference to the prior art, for example, part of the code in the example process.
As shown in fig. 1, the method for automatically generating the test case based on the path coverage software test includes the following steps:
in the first step, the input, output and decision of the program under test, loop branches are analyzed, and a Control Flow Graph (CFG) of the test function is drawn.
The analysis is performed for each input, output and judgment, loop branch, and based on these information, a Control Flow Graph (CFG) of the functional unit under test is drawn, as shown in fig. 2 and 3. And after the control flow graph is obtained, the number of paths existing in the tested program is obtained according to the circle complexity of the control flow graph. By analyzing FIG. 3, we find that there are 5 branch decision nodes {2,5,6,8,10} in the test program, and we number these nodes from 1 to 5.
From fig. 3, we can clearly recognize all the paths of the Triangle problem:
{0,0,0, N, N }, {0,0,1,0, N }, {0,0,1,1,0}, {0,0,1,1,1}, {1,1, N, N, N } and
{1,0,0,N,N},{1,0,1,0,N},{1,0,1,1,0},{1,0,1,1,1},{0,1,N,N,N}。
and secondly, determining the specific problem code of the tested program.
According to the definition of three input variables a, b, and c in the test question "Triangle", a, b, and c are positive integers in the range of [1, MAX _ VALUE ], where MAX _ VALUE represents a computer-expressible positive integer.
And thirdly, obtaining a corresponding adaptive value function benchmark function () according to the test program.
According to the branch distance-based calculation method proposed by us in table 1, we will obtain an adaptive value function for the test function "Triangle": at the first decision branch (c), the branch distance of the statement is calculated:
if(a<(b+c))&&(b<(a+c))&&(c<(a+b))
from the semantics of α < β in Table 1 we will judge a < (b + c), b < (a + c) and c < (a + b), respectively, where:
if(a<(b+c))v1=0;
else v1=a-(b+c)+K;
if(b<(a+c))v2=0;
else v2=b-(a+c)+K;
if(c<(a+b))v3=0;
else v3 ═ c- (a + b) + K; (K is a constant, we set to 10)
The branch distances v1, v2 and v3 of the three judgment branches are obtained according to the formula method, and "&" represents the semantic meaning of "α ^ β", so we need to sum the three branch distances:
Figure BDA0001394197290000081
four branch nodes in the next row (C) calculate the branch distance f (P) of the tested function judge node by using the rule in Table 1XJ) (where j is 1,2, …, branch number judged in Triangle), and the final adaptation value calculation functionThe test case adaptive value returned by the number BenchMarkfunction () is obtained by accumulating the branch distances of the judgment nodes through which the test cases pass:
Figure BDA0001394197290000082
(where k represents the number of branches passed by test case X).
And fourthly, randomly initializing the population.
For the test program Triangle, program inputs with lower bound lb ═ 1 and upper bound ub ═ MAX _ VALUE are selected, and then the population is randomly initialized within [ lb, ub ] using a uniform distribution.
And fifthly, iteratively updating the population by using a differential evolution algorithm, and recording a first test case covering the program path.
Selecting a differential evolution algorithm (DE) to iterate the population, wherein the size of the selected population is 50, analyzing the initial solution generated in the step (d) and the solution iteratively generated by the differential evolution algorithm (DE) in the step (e), judging which path of Triangle is covered by the test cases corresponding to the solutions, and recording the test case if the test case covers a path which is not covered before. Thus, after the iteration of the algorithm is finished, a set of test cases is obtained
Figure BDA0001394197290000083
(where k represents the number of paths owned by the program under test), each test XiAnd (i ═ 1,2, and k) covers a path different from other test cases in the set, namely, the path coverage of the whole tested program is completed.
And updating a record matrix C of the input dimension influence judgment branch node through a test case of each generation while searching the DE algorithm, wherein the matrix C has n rows and m columns, and the (i, j) th element of the matrix C represents the influence of the ith dimension of the input parameter on the jth branch judgment node of the test program. Analyzing whether the DE algorithm falls into a local optimal value or not through iterative updating of the DE algorithm of 10 generations each time, and if the DE algorithm falls into the local optimal value, re-initializing the population through uniform distribution in a [ lb, ub ] range in the similar step (d); if the local optimum is not trapped, finding a node which is not covered by the current test case from the uncovered path, finding the input data dimension influencing the node, finding the optimized dimension by a roulette mode according to the influence value in the matrix C, and carrying out dynamic step search.
The method of dynamic step search is as follows: for a dimension i in the range of [ lb, ub ], randomly selecting two values x, y in the range of [ lb, ub ] in the dimension i each time, and if x < y is not set, the difference between the two numbers x, y is required to be more than 0.5 x (ub-lb), taking | x-y | as an initial step length, and then performing binary search in the range of [ x, y ] to perform dynamic step length mode search.
And sixthly, detecting whether the iteration termination condition is met or not, if the iteration termination condition is not met, jumping back to the fifth step to continue execution, and if the iteration termination condition is met, outputting a final result.
The step is to judge whether the operation of the algorithm is finished or not, the iteration termination condition of a differential evolution algorithm (DE) is two, the first is that the algorithm already obtains all test cases covering the paths of the test program, the other is that the algorithm does not obtain the test cases covering all the paths of the test program after multiple iteration updates, and in the setting, the maximum iteration test is set to be Max 108. After the execution is finished, the algorithm outputs the recorded test case set covering the corresponding path.
Because of the large number of random factors involved in the fourth, fifth and sixth steps, our solution is not a method for determining how much time or cost to solve, and thus the steps are difficult to simulate.
But we finally find that we only find out the test cases of the five paths of {0,0,0, N }, {0,0,1,0, N }, {0,0,1,1,0}, {0,0,1,1,1}, {1,1, N }, but the test cases of the five paths of {1,0,0, N }, {1,0,1,0, 0, N }, {1,0,1,1,1}, {0,1, N } cannot be found, the problem is simple, we can see from the program source code of the Triangle function that isatringle is given a false after the execution of the program source code, and the judgment branch goes into the sixth, so the paths beginning with {1,0} in all paths are invalid, and the test cases of the path of the first path are given a value of 0, and the test cases of the path of the first path are given a value of 0,1, N, N, N } also has no test case.
From the example result, the effective path test case of the Triangle problem can be found by the method.

Claims (7)

1. The method for automatically generating the test case based on the path coverage software test is characterized by comprising the following steps of:
(a) analyzing input and output corresponding to the function of the input tested test program, obtaining a control flow graph CFG through judgment and circulation branches existing in the analysis program, and coding a path to be covered;
(b) determining problem codes according to the types and ranges of actual input and output data of the test problems;
(c) obtaining an adaptive value function for calculating an evaluation value of a test case by inputting a problem code determined according to a specific test problem in the step (b) and a preset method for calculating a branch distance to the control flow graph CFG obtained in the step (a);
(d) randomly initializing a population in a uniformly distributed mode within the value range of the test case;
(e) updating the iterative population with the population obtained in step (d) using a differential evolution algorithm (DE) and a convergence rate controller (CSC) and the fitness function obtained in step (c);
selecting a differential evolution algorithm (DE) to iterate the population, wherein the iterative formula of the DE is as follows: v. ofi=yi+F*(yj-yk) Wherein v isiIs the new test sample obtained, and yiIs the old test case before differential evolution, yjAnd ykTwo test cases are randomly selected from all solutions of a population; after the above calculation is completed, the cross operation of the differential evolution algorithm (DE) is performed to generate a [0,1 ]]Random number rand in between, if the size of rand is less than the preset cross probability PcThen the new solution is retained if the size of rand is larger than the preset crossover probability PcThen the solution just obtained is discarded and the solution is savedThe previous solution is left; when the differential evolution algorithm is used for iterative updating, the convergence speed of the DE algorithm is controlled by a Convergence Speed Controller (CSC), dynamic step search operation of relevant dimensions is carried out when the convergence speed of the DE algorithm is judged to be too low, the convergence speed of the algorithm is accelerated, and the operation of initializing partial dimensions of a population is carried out when the convergence speed of the DE algorithm is judged to be too high, so that the convergence speed of the algorithm is reduced; the dynamic step search operation method comprises the following steps: searching large step length in a set dimension range to find the position with the best adaptive value, searching in a smaller range according to the position until the step length is smaller than a preset value, and exhausting in the range smaller than the preset value to find the point with the highest adaptive value; establishing a new population individual obtained after the dimensionality dynamic step length search according to the data;
the speed reduction operator of the convergence rate controller (CSC) adds a region hit number statistical data structure, and partitions the range of program input variables each time before the program runs, specifically: the value range of the ith dimension of the test case X is [1,100], the test case X is averagely divided into 10 regions, the hitting times of each region are counted, and the region with the minimum hitting times of each dimension of the test case is selected and initialized when the speed reduction operation of a convergence rate controller (CSC) is carried out each time;
(f) recording the test cases covering the current uncovered paths of the tested programs in the population individuals in the steps (d) and (e);
(g) detecting whether an iteration termination condition of a differential evolution algorithm is met: if the condition is not met, jumping back to the step (e) to continue execution; and if the condition is met, outputting the recorded test case set covering the corresponding path.
2. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: in the step (a), adopting a unit test method for an input tested program, analyzing input and output and judging and circulating branches of a corresponding functional unit for each functional unit, and drawing a control flow graph CFG of the functional unit; and determining the codes of all paths according to a control flow graph CFG, firstly summarizing all judgment and circulation branches of a test program, setting the judgment and circulation branches to be 1-K, setting the path to be a character string with the length of N, if the path passes through a kth branch judgment node, the value of the kth bit of the path is a character '1' or a character '0', the character '1' indicates that the path is in the No direction, the character '0' indicates that the path is in the Yes direction, if the path does not pass through the kth branch judgment node, the character 'N' can be used for representing, and the path is coded in such a way, and all paths can be represented by a character string with the length of N.
3. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: in the step (b), analyzing the input and output data types and ranges of the tested program, and determining the codes of specific problems, specifically comprising: for a numerical data variable, it is necessary to determine whether the data is an integer or a floating-point number, and set a value range thereof; if the type of the variable is character type, an ASCII code symbol is represented by an integer in the range of [0,255], and a character string of length m is represented by m integers in the range of [0,255 ]; if the variable is an enumeration type, wherein the number of enumeration selections is k, using an integer in the range of [1, k ] to represent an input test case; for the case that the input and the output are the combination of the types, only the types of the input and the output need to be combined, and then a test case can be obtained.
4. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: in the step (c), the method for calculating the adaptive value of the test case comprises the steps of firstly determining which nodes and trends of the Control Flow Graph (CFG) generated in the step (a) the input test case X passes through, wherein a path formed by the test case X is called as PXThe test case is on the path PXThe evaluation value of the branch distance of the upper j-th node is denoted as f (P)XJ) at f (P)XJ) using two strategies in the calculation processThe first strategy, in response to the effect of the value function, is f (P) for the branch node direction that has been coveredXJ) the value will be set to 0 and the second strategy is for uncovered paths PXJ (th) node of
Figure FDA0002761609020000021
Figure FDA0002761609020000022
Where epsilon is a set constant that is,
Figure FDA0002761609020000023
then it represents that test case X is at the node
Figure FDA0002761609020000024
Upper branch distance; and by combining the two strategies, a self-adaptive test case adaptive value calculation function is realized.
5. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: analyzing the initial solution generated in the step (d) and the solution iteratively generated by the differential evolution algorithm (DE) in the step (e), judging which path of the test program is covered by the test case corresponding to the solutions, and recording the test case if the test case covers a path which is not covered before; thus, after the iteration of the algorithm is finished, a set of test cases is obtained
Figure FDA0002761609020000031
Where k represents the number of paths owned by the program under test, each test case XiA path different from other test cases in the set is covered, that is, the path coverage of the whole tested program is completed, i is 1,2, k.
6. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: in the step (g), two iteration termination conditions of the differential evolution algorithm (DE) are provided, wherein the first is to obtain a test case covering all paths of the test program, and the other is to obtain no test case covering all paths of the test program after repeated iteration updating, and a loop is skipped when one condition is met; and setting the maximum iteration times, and outputting the recorded test case set covering the corresponding path after the execution is finished.
7. The method for automatically generating the test case based on the path coverage software test as claimed in claim 1, wherein: in step (e), the convergence rate controller (CSC) operates as follows: firstly, defining a matrix C, wherein the matrix C has n rows and m columns, the (i, j) th element of the matrix C represents the influence of the ith dimension of an input parameter on the jth branch judgment node of a test program, updating the matrix C when a group of test cases are generated each time, comparing whether the trend of a certain judgment node is changed by comparing the change of numerical values of different dimensions, and if the trend is changed, adding one to the corresponding numerical value; after updating the matrix, after each iteration updating of the differential evolution algorithm (DE) of 10 generations, analyzing whether the differential evolution algorithm (DE) falls into a local optimal value, if the differential evolution algorithm (DE) falls into the local optimal value, selecting a proper input range [ lb, ub ] according to different input values of a test program, wherein lb is a value range lower bound, ub is a value range upper bound, and then reinitializing the population according to uniform distribution in the [ lb, ub ] range in the step (d); if the local optimum is not trapped, finding a node which is not covered by the current test case from the uncovered path, finding the input data dimension influencing the node, finding the optimized dimension by a roulette mode according to the influence value in the matrix C, and carrying out dynamic step search.
CN201710766422.3A 2017-08-30 2017-08-30 Automatic test case generation method based on path coverage software test Active CN107590073B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710766422.3A CN107590073B (en) 2017-08-30 2017-08-30 Automatic test case generation method based on path coverage software test

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710766422.3A CN107590073B (en) 2017-08-30 2017-08-30 Automatic test case generation method based on path coverage software test

Publications (2)

Publication Number Publication Date
CN107590073A CN107590073A (en) 2018-01-16
CN107590073B true CN107590073B (en) 2021-03-30

Family

ID=61051813

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710766422.3A Active CN107590073B (en) 2017-08-30 2017-08-30 Automatic test case generation method based on path coverage software test

Country Status (1)

Country Link
CN (1) CN107590073B (en)

Families Citing this family (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110377492B (en) * 2018-04-12 2022-05-17 南京慕测信息科技有限公司 Unit test case generation method based on method similarity
CN110377493B (en) * 2018-04-12 2022-05-17 南京慕测信息科技有限公司 Unit test case optimization method facing code readability
CN110399286B (en) * 2018-04-24 2023-05-12 西安邮电大学 Independent path-based automatic test data generation method
CN108710575B (en) * 2018-05-23 2020-11-24 华南理工大学 Unit test method based on automatic generation of path coverage test case
CN109376075B (en) * 2018-09-19 2022-04-22 奇安信科技集团股份有限公司 Processing method and device for generating optimal test coverage path of test object
CN111831532A (en) * 2019-04-15 2020-10-27 富士通株式会社 Method for constructing test scene and information processing equipment
CN110543421B (en) * 2019-08-31 2022-03-29 华南理工大学 Unit test automatic execution method based on test case automatic generation algorithm
CN111209192B (en) * 2019-12-30 2023-05-02 山东科技大学 Automatic test case generation method based on double-chaos whale optimization algorithm
CN112749082B (en) * 2020-05-11 2022-06-24 长江大学 Test case generation method and system based on DE-TH algorithm
CN112162932B (en) * 2020-10-30 2022-07-19 中国人民解放军国防科技大学 Symbol execution optimization method and device based on linear programming prediction
CN112286824B (en) * 2020-11-18 2022-08-02 长江大学 Test case generation method and system based on binary search iteration and electronic equipment
CN113468044B (en) * 2021-05-27 2022-06-24 长江大学 Test case generation method based on improved grey predictive evolution algorithm
CN113342699B (en) * 2021-07-26 2023-08-04 中南大学 Software radio compliance testing method and system
CN114064453B (en) * 2021-10-12 2023-04-07 华南理工大学 Software test case automatic generation method based on clustering and evolutionary algorithm
CN113742251B (en) * 2021-11-08 2022-01-28 山东建筑大学 Software test path generation method and system based on set evolution
CN114490316B (en) * 2021-12-16 2023-04-18 四川大学 Loss function-based automatic generation method for unit test case
CN114579435B (en) * 2022-02-23 2024-05-28 南京信息工程大学 Method for generating software test case
CN117472786B (en) * 2023-12-27 2024-04-12 道普信息技术有限公司 Automatic test case generation method and device, electronic equipment and storage medium
CN117520211A (en) * 2024-01-08 2024-02-06 江西财经大学 Random combination test case generation method and system based on multidimensional coverage matrix

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Differential Evolution Based on Self-Adaptive Fitness Function for Automated Test Case Generation;Han Huang等;《IEEE COMPUTATIONAL INTELLIGENCE MAGAZINE》;20170530;第46-55页 *
一种改进的遗传算法在测试用例中的应用研究;莫赞;《科技创新导报》;20150531(第5期);第247-250页 *
基于群智能优化算法的收敛控制器框架及其应用;叶树锦;《中国优秀硕学位士论文全文数据库信息科技辑》;20160215(第2期);第6-21页 *

Also Published As

Publication number Publication date
CN107590073A (en) 2018-01-16

Similar Documents

Publication Publication Date Title
CN107590073B (en) Automatic test case generation method based on path coverage software test
CN112328505B (en) Method and system for improving coverage rate of fuzz test
CN112699051B (en) Variant grouping method based on relevant input variables
CN110399286B (en) Independent path-based automatic test data generation method
CN109918307B (en) Path coverage test data generation method based on negative selection genetic algorithm
CN114626071B (en) Vulnerability-oriented fuzzy test method, system and medium
CN114064453B (en) Software test case automatic generation method based on clustering and evolutionary algorithm
CN114840857B (en) Intelligent contract fuzzy test method and system based on deep reinforcement learning and multi-stage coverage strategy
CN113468044B (en) Test case generation method based on improved grey predictive evolution algorithm
CN113407185A (en) Compiler optimization option recommendation method based on Bayesian optimization
CN106919504B (en) Test data evolution generation method based on GA algorithm
Ghiduk et al. Using genetic algorithms and dominance concepts for generating reduced test data
CN105988855B (en) Just-In-Time parameter optimization method and device
CN117453539A (en) Compiler defect positioning method based on large language model enabling
CN114780967B (en) Mining evaluation method based on big data vulnerability mining and AI vulnerability mining system
CN117149615A (en) Method and corresponding device for generating test case execution path
Ballal et al. Compiler optimization: A genetic algorithm approach
CN115022192B (en) Resource selection method and system for evolutionary game network information system
CN114064472B (en) Automatic software defect repairing acceleration method based on code representation
CN115248780A (en) Interface test case generation method and device
CN111444079A (en) Software defect repairing method and device
Hanh et al. A novel test data generation approach based upon mutation testing by using artificial immune system for Simulink models
CN114691518B (en) EFSM input sequence generation method based on deep reinforcement learning
Liu et al. MC/DC test data generation algorithm based on whale genetic algorithm
Chitty Exploiting tournament selection for efficient parallel genetic programming

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
TR01 Transfer of patent right

Effective date of registration: 20230112

Address after: No. 309E, 3rd Floor, Building 22, Shunlian Machinery City, No. 18, Xingye 4th Road, Guanglong Industrial Park, Chihua Community, Chencun Town, Shunde District, Foshan City, Guangdong Province, 528314

Patentee after: Microscience Intelligent Inspection (Foshan) Technology Co.,Ltd.

Address before: 510640 No. five, 381 mountain road, Guangzhou, Guangdong, Tianhe District

Patentee before: SOUTH CHINA University OF TECHNOLOGY

TR01 Transfer of patent right