Test case priority ordering method based on tabu particle swarm optimization
By introducing the taboo particle swarm algorithm into test case prioritization, the problem of insufficient local optimization capabilities and slow convergence speed is solved, more efficient test case sorting is achieved, and the risk of software defect release is reduced.
Patent Information
- Application Number
- CN202310177603.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-28
- Publication Date
- 2024-08-30
AI Technical Summary
The existing technology has problems with insufficient local optimization capabilities and slow convergence speed in test case prioritization, resulting in the software failing to execute the test cases associated with the change point within a limited time, increasing the risk of software defect release.
A test case prioritization method based on the tabu particle swarm algorithm is adopted. By introducing a tabu list and a random exchange combination, the algorithm's optimization capability is enhanced, preventing it from falling into local optimality, and improving the execution effectiveness of test cases.
It effectively solves the problem of test case sorting in a short period of time, improves the rate of regression test error detection, reduces the risk of program problems, and improves the execution efficiency of test cases.
Smart Images

Figure CN118567965A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of software testing, and in particular to a test case prioritization method based on a taboo particle swarm algorithm. Background Art
[0002] Software testing aims to improve work efficiency and test quality, and is a key link in building highly reliable software. In black box testing, testers often design test cases based on technical specifications or specifications. Generally, software requirements are first converted into test requirements, and then the test requirements are broken down into test items. Then, by designing test plans, test cases are designed for the test items to form a test case library. In regression testing, a simple maintenance strategy is to re-execute all existing test cases, but it is often not feasible to re-execute all test cases due to many reasons such as urgent project requirements and the inability of existing test cases to cover new test requirements.
[0003] Therefore, it is particularly important to preprocess the test cases. The test case prioritization technology is especially suitable for test scenarios where not all test cases can be executed due to insufficient test resources and limited time. Under the guidance of specific sorting criteria, the test cases are sorted from high to low in importance and executed in sequence, which can discover possible bugs in the program more quickly, thereby improving the efficiency of regression testing error detection.
[0004] Current research mainly focuses on code-based test case prioritization technology. According to the coverage of each test case on the program entity, a weight is set for it, and the greedy method is applied to guide the sorting of test cases. Some researchers have also tried to use typical machine learning methods to improve the execution effect of test case prioritization technology, and applied meta-heuristic search and clustering algorithms to test case prioritization technology. Among them, the particle swarm optimization algorithm uses a set of multidimensional vectors to represent different particles, and continuously corrects the flight direction and speed of the particles according to the individual optimal solution and the group optimal solution. Due to its relative simplicity, easy implementation, and few parameters, the algorithm can achieve good results in both continuous optimization problems and discrete optimization problems. Applying the particle swarm algorithm to the field of software testing can improve the efficiency of solving the test case prioritization problem and obtain satisfactory optimal sorting results in a relatively short time. However, when applying it, there will still be problems such as poor local optimization ability and slow convergence speed in the later stage. Summary of the invention
[0005] The technical problem to be solved by the present invention is to overcome the problems existing in the above-mentioned prior art and provide a test case prioritization method based on the taboo particle swarm algorithm, which does not rely on formalized software requirements, can achieve better results in a relatively short time, and effectively solve the problem of software defect release due to the limited time without executing the test cases with strong correlation with the change point, thereby effectively improving the rate of regression test error detection and reducing the risk of program problems. To achieve the above-mentioned invention purpose, the present invention adopts the following technical scheme:
[0006] The present invention provides a test case prioritization method based on the taboo particle swarm algorithm, which is characterized by applying the particle swarm algorithm to the field of software testing to improve the efficiency of solving the test case prioritization problem, and in the process of traditional particle swarm algorithm optimization, adding the taboo algorithm to randomly exchange the particle population to enhance the algorithm's optimization ability and prevent the algorithm from falling into the possibility of local optimality, thereby improving the effectiveness of test case execution. It is specifically divided into the following steps:
[0007] Step 1: Particle swarm encoding and initialization; the particle position is represented by an ordered test case number, and the present invention uses a real number encoding method to represent the serial number of each test case in the test case set.
[0008] Step 2: In order to avoid loops in the search process, a taboo table is introduced. First, the taboo table is set to empty;
[0009] Step three: Construct a fitness function: average branch coverage, effective execution time, and average defect detection efficiency; the present invention takes average branch coverage and effective execution time as optimization goals, and takes the defined defect detection rate as an evaluation indicator for test case sorting.
[0010] APBC stands for Average Branch Coverage. Right now TB v is the first branch B that can cover the vth branch in the program to be tested v The order of the test case in the test case execution sequence. Assuming that the number of branches covered in the test program after the test is executed is M, then M branches correspond to M such orders, and the sum of all orders is This allows the fitness function to be constructed.
[0011] EET represents the sum of the time it takes to execute test cases when the test case priority sequence first reaches full branch coverage; After executing the first m' test cases in the test case priority sequence, all branches of the program under test can be covered;
[0012] The average percentage of defect detection APFD can effectively evaluate the average defect efficiency of TCP. The calculation formula is:
[0013] Where n represents the number of valid test cases participating in the evaluation test in the test case set T, k represents the number of defects detected, and TFi (1≤i≤k) represents the position number of the first test case that detects defect i in this execution sequence. The value range of the APFD evaluation index is 0-100%. The higher the value, the faster the corresponding test case set detects defects and the better the sorting efficiency.
[0014] Step 4: Randomly initialize the population; set the population size to N, that is, the population contains N individuals. If D represents the population, then D = { <r 11 ,r 12 ,...,r 1n >,..., <r 21 ,r 22 ,...,r 2n >,..., <r w1 ,r w2 ,...,r wn >,..., <r N1 ,r N2 ,...,r Nn >}, where <r w1 ,r w2 ,...,r wn > represents the wth individual in the population; the upper speed limit V max , maximum number of iterations MAX;
[0015] Step 5: Calculate the fitness value of each particle, and update the optimal solution of the individual and the optimal solution of the group: if the fitness value of the particle is due to the individual extreme value, update it; if the fitness value of the particle is better than the global extreme value, update it;
[0016] Step 6: Update the position and velocity of the particle; the solution of each particle corresponds to the position of the particle, and the velocity corresponding to the traditional particle swarm algorithm is as follows:
[0017] v nex =ω×v cur +c1×r1×(p * -x cur )+c2×r2×(g * -x cur );
[0018] x nex =x cur +v nex ;
[0019] Among them, w, c1, c2 are inertia coefficient, individual cognition coefficient and social cognition coefficient respectively; v curand x cur is the current velocity and displacement; v nex and x nex is the speed and displacement of the next step; p * The best position that an individual has ever experienced; g * is the global optimal position; r1, r2 are random numbers in a group (0, 1). Based on the above formula, the particle population is updated. The taboo algorithm is added to the traditional particle swarm algorithm, and the particle swarm is randomly exchanged and combined to enhance the algorithm's optimization ability and prevent the algorithm from entering the local optimum.
[0020] Step 7: Perform random crossover mutation on each particle in the particle swarm and calculate the fitness of the mutated particles.
[0021] Step 8: If the new fitness is better than the group optimal solution, update the group optimal solution in the taboo table. If not, go to step 9.
[0022] Step 9: If the new fitness solution is better than the solution corresponding to the particle before the transformation, then add this particle and its corresponding liberation into the taboo table, that is, update the taboo table;
[0023] Step 10: Obtain the priority sequence of new test cases;
[0024] Step 11: If the number of iterations is greater than the set maximum number of iterations, the optimal solution is output; if not, go to step 5.
[0025] The test case prioritization method based on the taboo particle swarm algorithm of the present invention has the following advantages:
[0026] 1. In order to evaluate the completeness and effectiveness of software testing, a general evaluation index based on requirements is proposed to measure the satisfaction degree of a given set of test cases, so as to discover the defects in the software as early as possible, which is used as the goal of test case prioritization.
[0027] 2. Before the test case is executed, the tester cannot predict the number of defects in the program to be tested that will be found during the test case execution. The coverage information is used to guide the priority of the test cases. In addition, the effective execution time is used to calculate the total time required to execute the test case when the maximum statement coverage is first reached, which is used as the optimization target.
[0028] 3. The standard particle swarm algorithm has the characteristics of simple structure, few parameters, easy interaction mechanism, and strong global search ability. Compared with other swarm intelligence algorithms, it has great advantages in solving continuous or discrete multi-objective optimization problems. However, with the continuous iteration of the algorithm, the diversity of the particle population will also decrease in the evolution, which is prone to premature convergence, and then cause the algorithm to fall into the local optimum. A particle swarm algorithm with a taboo algorithm is proposed for test case prioritization, which can be directly used for black box testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 It is a flow chart of the present invention DETAILED DESCRIPTION
[0030] The present invention is further described below in conjunction with the accompanying drawings. The following content is only used to more clearly illustrate the technical solution of the present invention and cannot be used to limit the protection scope of the present invention.
[0031] Reference Figure 1 The specific implementation process of the present invention is as follows:
[0032] Step 1: Particle swarm encoding and initialization;
[0033] For a program to be tested, use the designed test case set to test it and record the branch coverage of the test case on the test program. If the source program of a product has 10 branches in total, use 215 test cases to test it.
[0034] Step 1.1: Test case prioritization problem For a given program to be tested and a set of test cases, an individual represents a test case prioritization sequence. The test case prioritization sequence is an ordered sequence of test case numbers, that is, each individual is encoded as an ordered test case number string. In this example, the length of the individual encoding is the number of test cases, 215;
[0035] Step 1.2: If the test case set is represented by T, T = {T1, T2, ..., T i , ..., T n}, where T i (1≤i≤n) is the i-th test case in the test case set. The size of the constructed branch coverage information matrix is 10*215. The range of statement numbers in the program to be tested is 1 to 10, and the range of test case numbers is 1 to 215. If the i-th test case covers the j-th branch during execution, then A ij =1, otherwise A ij =0;
[0036] Step 2: In order to avoid loops during the search process, a taboo table is introduced. First, the taboo table is set to empty.
[0037] Step three: Construct a fitness function: average branch coverage, effective execution time, and average defect detection efficiency; the present invention takes average branch coverage and effective execution time as optimization goals, and takes the defined defect detection rate as an evaluation indicator for test case sorting.
[0038] For any individual, TB v is the first branch B that can cover the vth branch in the program to be tested v The order of the test case in the test case execution sequence. Assuming that the number of branches covered in the test program after the test is executed is M, then M branches correspond to M such orders, and the sum of all orders is From this, we can construct the fitness function, APBC represents the average branch coverage, TB v (1≤v≤10) can be calculated using the branch coverage information matrix A: for the covered branch B v , find the order of the first test case that covers the branch in A in the test case sequence, then this order is TB v The value of
[0039] EET represents the sum of the time it takes to execute test cases when the test case priority sequence first reaches full branch coverage;
[0040] In order to test the effectiveness of the taboo particle swarm algorithm proposed in this invention in solving the problem of test case prioritization, the average percentage of defect detection APFD is introduced. Because the test case set of the program to be tested contains many redundant test cases, in order to ensure the reliability of the test results, before the actual experiment begins, it is necessary to select a target test case set with less redundancy from the test case library, and its coverage rate reaches the maximum block coverage rate of the test case library.
[0041] Step 4: Randomly initialize the population; set the population size to 50, that is, the population contains N individuals. If D represents the population, then D = { <r 11 ,r 12 ,...,r 1215 >,..., <r 21 ,r 22 ,...,r 2215 >,..., <r 501 ,r 502 ,...,r 50215 >}, where <r 31 ,r 32 ,...,r 3215 >
[0042] Represents the third individual in the population; upper speed limit V max, maximum number of iterations 100;
[0043] Step 5: Calculate the fitness value of each particle, update the optimal solution of the individual and the optimal solution of the group: calculate the average branch coverage and effective execution time of each individual; obtain two arrays consisting of N fitness values, represented as {APBC1, APBC2, ..., APBC 100} and {EET1, EET2, ..., EET 100}, if the particle fitness value is due to the individual extreme value, update it; if the particle fitness value is better than the global extreme value, update it;
[0044] Step 6: Update the position and velocity of the particle; in the taboo search algorithm, the optimal value obtained in each iteration of the algorithm will be put into the taboo table. If the global extreme value is also tabooed in each iteration of the particle, it is easy to destroy the stability of the algorithm and the overall flight direction of the particle. Therefore, after a certain number of iterations of the particle swarm algorithm, the global extreme value obtained is tabooed, which can not only prevent the algorithm from falling into the local optimum, but also maintain the original stability of the particle swarm algorithm. When the global extreme value is tabooed, a particle in the particle swarm is randomly selected, and its individual extreme value is used as the global extreme value of the particle swarm, and the search is performed according to the particle swarm algorithm.
[0045] Step 7: Perform random crossover mutation on each particle in the particle swarm and calculate the fitness of the mutated particles.
[0046] Step 8: If the new fitness is better than the group optimal solution, update the group optimal solution in the taboo table. If not, go to step 9.
[0047] Step 9: If the new fitness solution is better than the solution corresponding to the particle before the transformation, then add this particle and its corresponding liberation into the taboo table, that is, update the taboo table;
[0048] Step 10: Obtain the priority sequence of new test cases;
[0049] Step 11: If the number of iterations is greater than the set maximum number of iterations, the optimal solution is output; if not, go to step 5.
Claims
1. A test case prioritization method based on taboo particle swarm algorithm, characterized in that: The following steps are involved: Step 1: Particle swarm encoding and initialization; the particle position is represented by an ordered test case number, and the present invention uses a real number encoding method to represent the serial number of each test case in the test case set; Step 2: In order to avoid loops in the search process, a taboo table is introduced. First, the taboo table is set to empty; Step 3: Construct a fitness function: average branch coverage, effective execution time, and average defect detection efficiency; the present invention uses average branch coverage and effective execution time as optimization targets, and uses the defined defect detection rate as an evaluation indicator for test case ranking; Step 4: Randomly initialize the population; set the population size to N, that is, the population contains N individuals. If D represents the population, then D = { <r 11 ,r 12 ,...,r 1n >,..., <r 21 ,r 22 ,...,r 2n >,..., <r w1 ,r w2 ,...,r wn >,..., <r N1 ,r N2 ,...,r Nn >}, where <r w1 ,r w2 ,...,r wn > represents the wth individual in the population; the upper speed limit V max , maximum number of iterations MAX; Step 5: Calculate the fitness value of each particle, and update the optimal solution of the individual and the optimal solution of the group: if the fitness value of the particle is due to the individual extreme value, update it; if the fitness value of the particle is better than the global extreme value, update it; Step 6: Update the position and velocity of the particle; the solution of each particle corresponds to the position of the particle, and the velocity corresponding to the traditional particle swarm algorithm is as follows: v nex =ω×v cur +c1×r1×(p * -x cur )+c2×r2×(g * -x cur ); x nex =x cur +v nex ; Among them, w, c1, c2 are inertia coefficient, individual cognition coefficient and social cognition coefficient respectively; v cur and x cur is the current velocity and displacement; v nex and x nex is the speed and displacement of the next step; p * The best position that an individual has ever experienced; g * is the global optimal position; r1, r2 are random numbers in a group (0, 1); based on the above formula, the particle population is updated. The taboo algorithm is added to the traditional particle swarm algorithm, and the particle swarm is randomly exchanged and combined to enhance the algorithm's optimization ability and prevent the algorithm from entering the local optimum; Step 7: Perform random crossover mutation on each particle in the particle swarm and calculate the fitness of the mutated particles; Step 8: If the new fitness is better than the group optimal solution, update the group optimal solution in the taboo table. If not, go to step 9; Step 9: If the new fitness solution is better than the solution corresponding to the particle before the transformation, then add this particle and the corresponding liberation into the taboo table, that is, update the taboo table; Step 10: Obtain the priority sequence of new test cases; Step 11: If the number of iterations is greater than the set maximum number of iterations, the optimal solution is output; if not, go to step five.
