Minimum test case set generation method of genetic algorithm based on combinatorial optimization

By building a simplified orderly binary decision diagram and improving genetic algorithm, and optimizing test case set generation, the problem of low efficiency and low coverage in the existing technology is solved, and efficient and full coverage test case set generation is achieved.

CN120371693APending Publication Date: 2025-07-25JIANGSU UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510415450.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

In the prior art, the problem of low generation efficiency and low coverage of test cases, especially in high-dimensional, nonlinear, and multimodal search spaces, the convergence of genetic algorithms is affected by the cross probability and mutation probability strategies.

Method used

By constructing a causal graph and simplifying it into a simplified orderly binary decision graph (ROBDD), combined with improved genetic algorithms, tournament selection, single-point cross-mutation operation is adopted, and cross-mutation probability is dynamically adjusted by improving the rate of improvement, and the test case set generation is optimized.

Benefits of technology

It effectively solves the problem of path explosion, reduces testing costs, improves the generation efficiency and coverage of test case sets, increases the convergence speed by 25%-40%, and reduces the scale of the generated test case set by 30%-50%, and reaches 100%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371693A_ABST
    Figure CN120371693A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a method for generating a minimum test case set of a genetic algorithm based on combinatorial optimization. Comprising the following steps: S1, extracting a logic dependency relationship in software, constructing a causal diagram, mapping a conditional branch and variable relationship into a Boolean expression, simplifying the causal diagram, merging invalid paths, reducing input, and converting the Boolean expression into a simplified ordered binary decision diagram; s2, according to the simplified ordered binary decision diagram obtained in the step 1, a combination number is obtained, and the combination number is the number of every two combinations of parameters in the simplified ordered binary decision diagram; and S3, optimizing and simplifying the ordered binary decision diagram by adopting an improved genetic algorithm to obtain an optimal minimum test case set. According to the method, the causal diagram is simplified, the binary decision diagram is simplified into a simplified ordered binary decision diagram, input path branches are reduced, the problem of path explosion is effectively solved, and the cost of test work is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization. Background Art

[0002] There are mainly two traditional software test case design methods. One is to manually write test content and form a test case document according to the requirements of test case design methods such as equivalence class partitioning, boundary value analysis, and error guessing method based on the analysis results of software functional requirements. The other is to construct a prototype use case library with the technical characteristics of historical similar software, and identify and screen the use case features manually, and then modify them appropriately for the software system under test.

[0003] In recent years, the idea of transforming the generation and minimization of test cases into combinatorial optimization has emerged. Since the genetic algorithm is particularly good at dealing with high-dimensional, non-linear, and multimodal search spaces, and is especially suitable for minimizing the combinatorial optimization problem in test case selection while maximizing the path coverage rate, many scholars have begun to study the automatic generation method of test cases based on the genetic algorithm. In the genetic algorithm, the selection strategy of the crossover probability and mutation probability is a key factor affecting the algorithm behavior and performance, which will directly affect the convergence of the algorithm. Summary of the Invention

[0004] In order to solve the problems of low efficiency and low coverage rate existing in the test case generation technology in the above-mentioned prior art, the present invention proposes a method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization.

[0005] The present invention is realized through the following technical solutions: including the following steps:

[0006] S1. Extract the logical dependency relationship in the software, construct a causal graph, map the conditional branch and variable relationship into a Boolean expression, simplify the causal graph, merge and reduce the input of invalid paths, and convert the Boolean expression into a reduced ordered binary decision diagram ROBDD;

[0007] S2. Obtain the combination number according to the reduced ordered binary decision diagram ROBDD obtained in step 1;

[0008] S3. Optimize the reduced ordered binary decision diagram ROBDD by using an improved genetic algorithm to obtain an optimal minimized test case set.

[0009] As a further preference, the specific steps of step S1 are as follows:

[0010] S11. Extract the logical dependency relationship in the software, construct a causal graph, and convert the conditional branch and event dependency relationship in the causal graph into a Boolean expression;

[0011] S12. Sort all variables in the Boolean expression;

[0012] S13. Expand the Boolean expression layer by layer according to the variable order to generate the original binary decision diagram;

[0013] S14. Simplify the binary decision diagram;

[0014] S15. Delete the paths in the binary decision diagram that cannot reach the final value of 1 to obtain the reduced ordered binary decision diagram ROBDD.

[0015] As a further preference, the specific steps of step S3 are as follows:

[0016] S31. Randomly generate the first-generation population according to the reduced ordered binary decision diagram ROBDD;

[0017] S32. Take the first-generation population randomly generated in step S31 as the parental population;

[0018] S33. Take the coverage rate of the combination number obtained in step 2 according to a single test case set as the fitness function to obtain the fitness value f of the single test case set. The formula is as follows:

[0019]

[0020] In the formula, fit(x i ) is the fitness function; n(x i ) is the number of paired combinations covered by the i-th individual in the offspring; represents the total number of paired combinations of k inputs;

[0021] S34. Adopt the tournament selection operator, randomly select N non-repeating operators in the parental population, compare their fitness values, and select the operator with the highest fitness value among them to add to the offspring. Repeat this step until the complete offspring is generated. The number of individuals in the complete offspring is equal to the number of individuals in the parental population;

[0022] S35. Perform crossover and mutation operations on the complete offspring generated in step S34, update the complete offspring, and calculate the fitness values of all individuals in the updated complete offspring to obtain the highest fitness value in the current iteration;

[0023] S36. Compare the highest fitness value in the current iteration with the historical highest fitness value. If the highest fitness value in the current iteration is higher than the historical highest fitness value, update the historical highest fitness value and retain the complete offspring of the current iteration; otherwise, keep the historical highest fitness value and its complete offspring unchanged;

[0024] S37. If the highest fitness value obtained in step S36 is equal to 1, end the iteration and output the current complete offspring as the optimal minimized test case set; otherwise, based on the current iteration number, obtain the current improvement rate, the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals to be grabbed from the population for each time in the next iteration. Use the complete offspring after crossover and mutation in the current iteration as the parental population, and execute steps S34 to S36 according to the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals to be grabbed from the population for each time in the next iteration.

[0025] As a further preference, the specific steps of step S14 are as follows:

[0026] S141. Merge isomorphic subgraphs: If two nodes have the same variables and the 0 / 1 branches point to the same child node, merge them into one node.

[0027] S142. Delete redundant nodes: If the 0-branch and 1-branch of a certain node point to the same child node, directly delete this node and make the parent node of this node point to this child node.

[0028] As a further preference, the formula for obtaining the current improvement rate in step S37 is as follows:

[0029]

[0030] In the formula, IR is the current improvement rate; f max (t) is the highest fitness value in the current iteration; f max (t - 1) is the highest fitness value in the previous iteration; t is the current iteration number.

[0031] As a further preference, the formulas for obtaining the crossover rate for the next iteration and the mutation rate for the next iteration in step S37 are as follows:

[0032]

[0033] In the formula, α is a preset constant. If the improvement rate exceeds this constant, it means that the fitness has a large increase in this iteration, thus accelerating the convergence; P c is the crossover rate; P v is the mutation rate; P c ’ is the crossover rate for the next iteration; P v ’ is the mutation rate for the next iteration.

[0034] As a further preference, the formula for obtaining the number of individuals to be grabbed from the population for each time in the next iteration in step S37 is as follows:

[0035]

[0036] where \(t\) is the current iteration number; \(N\) t+1 is the number of individuals captured each time for the next iteration; represents rounding down.

[0037] As a further preference, the principle for sorting all variables in the Boolean expression in step S12 is the high-frequency first principle.

[0038] As a further preference, the crossover and mutation operation in step S35 is as follows: The crossover operation is performed in a single-point crossover manner. A crossover point is randomly selected, and the genes after the crossover point are exchanged with adjacent individuals. Subsequently, each individual is mutated separately at the current mutation rate.

[0039] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0040] 1. The present invention simplifies the causal graph, simplifies the Binary Decision Diagram (BDD) to the Reduced Ordered Binary Decision Diagram (ROBDD), reduces the input path branches, effectively solves the problem of path explosion, and reduces the cost of the testing work.

[0041] 2. The present invention introduces a dynamic crossover rate and mutation rate adjustment strategy based on the improvement rate (IR), and can automatically optimize the search process according to the population evolution state. When the fitness is significantly improved, the crossover / mutation probability is reduced to retain high-quality genes, and when the convergence stagnates, the mutation probability is increased to jump out of the local optimum. Experiments show that this mechanism improves the algorithm convergence speed by about 25%-40%, and at the same time reduces the number of ineffective iterations.

[0042] 3. The present invention takes the pairwise combination coverage rate as the core index of the fitness function, combines the mathematical rigor of combinatorial testing with the global search ability of the genetic algorithm. By forcing all pairwise input parameter combinations to be covered, on the premise of ensuring test completeness, the scale of the generated test case set is reduced by 30%-50% compared with the traditional genetic algorithm, and at the same time, the input domain combination coverage rate reaches 100%.

[0043] 4. The present invention adds a combinatorial testing improved genetic algorithm to the automatic test case set generator, and can inherit the advantages of combinatorial testing and improved genetic algorithm, ensuring the quality of test cases and the efficiency of testing.

[0044] 5. The present invention has the characteristics of reasonable design, simple structure, convenient use, multi-purpose, etc., and has good popularization and application value. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1This is the overall flowchart of the present invention.

[0046] Figure 2 This is the flowchart of the improved genetic algorithm in the generation method of the present invention. Detailed implementation manners

[0047] The advantages and features of the present invention will be illustrated and explained through the non - restrictive description of the following preferred embodiments, which are given only as examples with reference to the accompanying drawings.

[0048] As Figure 1 shown, the present invention provides a method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization, including the following steps:

[0049] Step 1: Extract the logical dependency relationships in the software, construct a causal graph, map the conditional branches and variable relationships into Boolean expressions, simplify the causal graph, merge and cut the input by combining invalid paths, and convert the Boolean expressions into a reduced ordered binary decision diagram (ROBDD).

[0050] Step 11: Extract the logical dependency relationships in the software, construct a causal graph, and convert the conditional branches and event dependency relationships in the causal graph into Boolean expressions;

[0051] Step 12: Sort all variables in the Boolean expressions;

[0052] Sorting the variables in the Boolean expressions is usually based on the execution priority in the causal graph or a heuristic strategy, such as the principle of giving priority to high - frequency variables.

[0053] Step 13: Expand the Boolean expressions layer by layer according to the variable order to generate the original binary decision diagram;

[0054] Step 14: Simplify the binary decision diagram;

[0055] Step 141: Merge isomorphic sub - graphs: If two nodes have the same variables and their 0 / 1 branches point to the same sub - nodes, they are merged into one node;

[0056] Step 142: Delete redundant nodes: If the 0 - branch and 1 - branch of a certain node point to the same sub - node, directly delete this node and make the parent node of this node point to this sub - node;

[0057] Step 15: Delete the paths in the binary decision diagram that cannot reach the final value 1 to obtain the reduced ordered binary decision diagram ROBDD.

[0058] The reduced ordered binary decision diagram ROBDD here is the input domain of the software to be tested after reduction. This step can reduce the input domain of the software to be tested, thereby reducing the test cost.

[0059] Step 2: Obtain the combination number based on the reduced ordered binary decision diagram (ROBDD) obtained in Step 1. The combination number is the number of pairwise combinations of the parameters in the ROBDD, that is, the number of pairwise combinations of the parameters in the input domain of the software under test.

[0060] Step 3: Optimize the reduced ordered binary decision diagram (ROBDD) using an improved genetic algorithm to obtain an optimal minimized test case set.

[0061] As Figure 2 shown, it is the flowchart of the improved genetic algorithm of the present invention.

[0062] Step 31: Randomly generate the first-generation population according to the reduced ordered binary decision diagram (ROBDD).

[0063] The generation of the first-generation population is randomly generated in the input domain space of the software under test, that is, the input domain of the software under test simplified by Step 1, which is the reduced ordered binary decision diagram (ROBDD).

[0064] Step 32: Use the first-generation population randomly generated in Step 31 as the parental population to drive the software under test to execute.

[0065] Generally, for a certain number of inputs of the software under test, the minimum number of test cases required to cover all pairwise combinations is fixed.

[0066] Step 33: Use the coverage rate of the combination number obtained in Step 2 by a single test case set as the fitness function to obtain the fitness value f of the single test case set. The formula is as follows:

[0067]

[0068] In the formula, fit(x i ) is the fitness function, and the obtained value is the fitness value f of the single test case set; n(x i ) is the number of pairwise combinations covered by the i-th individual in the offspring; represents the total number of pairwise combinations of k inputs.

[0069] The coverage rate of the combination number obtained in Step 2 by the single test case set in this step characterizes the fitness of the single test case set for the test. The higher the fitness value f, the higher the coverage rate, which means the more comprehensive the test work and the higher the completeness of the software test.

[0070] Step 34: Select operators using the tournament method. Randomly select N non-repeating operators from the parental population, compare their fitness values, and select the operator with the highest fitness value to add to the offspring. Repeat this step until a complete offspring is generated, where the number of individuals in the complete offspring is equal to the number of individuals in the parental population.

[0071] Select offspring using the tournament method, enabling the algorithm to converge faster.

[0072] Step 35: Perform crossover and mutation operations on the complete offspring generated in Step 34. Use the single-point crossover method for the crossover operation. Randomly select the crossover point and exchange the genes after the crossover point with adjacent individuals. Subsequently, perform mutation operations on each individual separately at the current mutation rate, update the complete offspring, and calculate the fitness values of all individuals in the updated complete offspring to obtain the highest fitness value at the current iteration.

[0073] Using the single-point crossover method can enable the population to explore new gene spaces, thus making individuals diverse.

[0074] Step 36: Compare the highest fitness value at the current iteration with the historical highest fitness value. If the highest fitness value at the current iteration is higher than the historical highest fitness value, update the historical highest fitness value and retain the complete offspring of the current iteration; otherwise, keep the historical highest fitness value and its complete offspring unchanged.

[0075] Step 37: If the highest fitness value obtained in Step 36 is equal to 1, end the iteration and output the current complete offspring as the optimal minimized test case set; otherwise, based on the current iteration number, obtain the current improvement rate, the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals grabbed from the population each time for the next iteration. Use the complete offspring that has undergone crossover and mutation in the current iteration as the parental population, and execute Steps 34 to 36 according to the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals grabbed from the population each time for the next iteration. The formulas for obtaining the current improvement rate, the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals grabbed from the population each time for the next iteration are as follows:

[0076]

[0077]

[0078] In the formula, IR is the current improvement rate; f max (t) is the highest fitness value at the current iteration; f max (t - 1) is the highest fitness value at the previous iteration; α is a preset constant. If the improvement rate exceeds this constant, it represents a large increase in fitness in this iteration, thus accelerating convergence; P c is the crossover rate; P vis the mutation rate; P c ’ is the crossover rate for the next iteration; P v ’ is the mutation rate for the next iteration; t is the current iteration number; N t+1 is the number of individuals captured each time for the next iteration; represents rounding down.

[0079] Judge whether the algorithm stop condition is satisfied. The stop condition of the algorithm is that the algorithm stops when the set of test cases represented by the population can cover all input pair combinations, that is, the highest fitness value of the population individuals is equal to 1.

[0080] The method for generating a minimized test case set based on combinatorial optimization and improved genetic algorithm of the present invention simplifies the cause - effect graph to merge and cut invalid paths to reduce inputs, improves the genetic algorithm to solve a set of optimized test case sets. In each step of the evolutionary calculation process, the generated test case set is calculated with the maximum number of input combinations as the fitness function to generate the next generation population, and the relevant probabilities are adjusted in real time. After multiple generations of evolution, the optimal population is obtained or the specific loop limit condition is exceeded and the process ends.

[0081] In addition to the above - mentioned embodiments, the present invention may have other implementation manners. All technical solutions formed by equivalent replacement or equivalent transformation fall within the protection scope required by the present invention.

Claims

1. A method for generating a minimized test case set based on a genetic algorithm of combinatorial optimization, characterized in that: It includes the following steps: S1. Extract the logical dependencies in the software, construct a causal graph, map the conditional branches and variable relationships into Boolean expressions, simplify the causal graph, merge and reduce the input by combining invalid paths, and convert the Boolean expressions into a reduced ordered binary decision diagram (ROBDD); S2. Obtain the combination number based on the reduced ordered binary decision diagram (ROBDD) obtained in step S1; S3. Optimize the reduced ordered binary decision diagram (ROBDD) using an improved genetic algorithm to obtain an optimal minimized test case set.

2. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 1, wherein: The specific steps of step S1 are as follows: S11. Extract the logical dependencies in the software, construct a causal graph, and convert the conditional branches and event dependencies in the causal graph into Boolean expressions; S12. Sort all the variables in the Boolean expressions; S13. Expand the Boolean expressions layer by layer according to the variable order to generate an original binary decision diagram; S14. Simplify the binary decision diagram; S15. Delete the paths in the binary decision diagram that cannot reach the final value 1 to obtain a reduced ordered binary decision diagram (ROBDD).

3. The method for generating a minimized test case set based on the genetic algorithm of combinatorial optimization according to claim 2, wherein: The specific steps of step S3 are as follows: S31. Randomly generate the first-generation population based on the reduced ordered binary decision diagram (ROBDD); S32. Use the first-generation population randomly generated in step S31 as the parental population; S33. Use the coverage rate of the combination number obtained in step 2 by a single test case set as the fitness function to obtain the fitness value f of the single test case set. The formula is as follows: where fit(x i ) is the fitness function; n(x i ) is the number of paired combinations covered by the i-th individual in the offspring; represents the total number of paired combinations of k inputs; S34. Adopt a tournament selection operator, randomly select N non-repeating operators from the parental population, compare their fitness values, and select the operator with the highest fitness value among them to add to the offspring. Repeat this step until a complete offspring is generated; S35. Perform crossover and mutation operations on the complete offspring generated in step S34, update the complete offspring, and calculate the fitness values of all individuals in the updated complete offspring to obtain the highest fitness value in the current iteration; S36. Compare the highest fitness value in the current iteration with the historical highest fitness value. If the highest fitness value in the current iteration is higher than the historical highest fitness value, update the historical highest fitness value and retain the complete offspring of the current iteration; Otherwise, keep the historical highest fitness value and its complete offspring unchanged; S37. If the highest fitness value obtained in step S36 is equal to 1, end the iteration and output the current complete offspring as the optimal minimized test case set; otherwise, based on the current iteration number, obtain the current improvement rate, the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals grabbed each time for the next iteration. Use the complete offspring that has undergone crossover and mutation in the current iteration as the parental population, and perform steps S34 to S36 according to the crossover rate for the next iteration, the mutation rate for the next iteration, and the number of individuals grabbed each time for the next iteration.

4. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 3, characterized in that: The specific steps of step S14 are as follows: S141. Merge isomorphic subgraphs: If two nodes have the same variables and the 0 / 1 branches point to the same sub-nodes, they are merged into one node; S142. Delete redundant nodes: If the 0-branch and 1-branch of a certain node point to the same child node, directly delete this node and make the parent node of this node point to this child node.

5. The method for generating a minimized test case set based on the genetic algorithm of combinatorial optimization according to claim 3, wherein: The formula for obtaining the current improvement rate in step S37 is as follows: Wherein, IR is the current improvement rate; f max (t) is the highest fitness value of the current iteration; f max (t - 1) is the highest fitness value of the previous iteration; t is the current iteration number.

6. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 5, characterized in that: The formulas for obtaining the crossover rate for the next iteration and the mutation rate for the next iteration in step S37 are as follows: Where α is a preset constant. If the improvement rate exceeds this constant, it means that the fitness increase in this iteration is large, thus accelerating convergence; P c is the crossover rate; P v is the mutation rate; P c ’ is the crossover rate for the next iteration; P v ’ is the mutation rate for the next iteration.

7. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 6, wherein: The formula for obtaining the number of individuals captured each time in the next iteration in step S37 is as follows: where t is the current iteration number; N t+1 is the number of individuals captured each time for the next iteration; represents rounding down.

8. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 3, characterized in that: The principle for sorting all variables in the Boolean expression in step S12 is the principle of high frequency first.

9. The method for generating a minimized test case set based on a genetic algorithm for combinatorial optimization according to claim 3, wherein: The crossover and mutation operation in step S35 is as follows: The crossover operation is carried out in the way of single-point crossover. Randomly select the crossover point and exchange the genes after the crossover point with the adjacent individual. Subsequently, perform the mutation operation on each individual separately with the current mutation rate.