Heuristic test case automatic generation method and system combined with information entropy
By combining the heuristic test case generation method based on information entropy, and utilizing particle swarm optimization and redundant test case removal, the problem of insufficient path and branch coverage in traditional methods is solved, achieving efficient and optimized test case set generation.
Patent Information
- Application Number
- CN202511429732.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-09
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2045-10-09
AI Technical Summary
Traditional test case generation methods struggle to simultaneously achieve path coverage and branch coverage, resulting in critical logic paths of the software not being detected, impacting stability and reliability. Furthermore, the generated test case sets are redundant, wasting time and resources and reducing testing efficiency.
A heuristic test case generation method combining information entropy is adopted. Through particle swarm optimization and redundant test case elimination, information entropy is used to evaluate the diversity and coverage of the test case set, thereby optimizing the test case set generation process.
It achieves diversity optimization of test case sets, improves path and branch coverage, reduces redundant test cases, and enhances testing efficiency and the breadth and uniformity of coverage.
Smart Images

Figure CN120909946B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of software testing, and in particular, relates to a heuristic test case automatic generation method and system combined with information entropy. BACKGROUND
[0002] In software testing, test case design plays a key role in ensuring software quality, and the effectiveness of test cases directly affects the probability of discovering potential defects in software and the final quality level of software. However, the current traditional test case generation methods, such as manual design and random generation, have obvious defects. Manual design of test cases relies on the experience and professional knowledge of testers, not only consuming a large amount of human and time costs, but also being difficult to comprehensively cover all logical paths and branch conditions of the program due to the limitation of human factors; although random generation of test cases improves the generation efficiency to a certain extent, it often generates test case sets in a chaotic manner, which is difficult to accurately cover the key logic of the program.
[0003] Overall, the traditional methods are difficult to balance path coverage and branch coverage at the same time. Insufficient path coverage will cause the key logic path of the software to be undetected, affecting stability and reliability, and insufficient branch coverage will miss important conditional branches. In addition, due to the inability to effectively balance the two coverage rates, the test case sets generated by the traditional methods often contain a large number of redundant cases, which not only wastes testing time, computing resources, etc., but also increases the difficulty of analyzing test results and reduces testing efficiency. SUMMARY
[0004] In order to solve the above technical problems, the present application provides a heuristic test case automatic generation method and system combined with information entropy.
[0005] In a first aspect, the present application provides a heuristic test case automatic generation method combined with information entropy, including initialization, particle swarm iterative optimization and redundant test case elimination.
[0006] The initialization includes: taking a test case set as a particle, initializing the particle swarm and the velocity vector of the particle, and calculating the information entropy to verify the initialization result; a test case set contains a plurality of test cases; a particle swarm contains a plurality of particles.
[0007] The particle swarm iterative optimization comprises: iteratively updating the speed of the particle according to the inertia weight, the learning factor, the random factor, the individual historical optimal solution and the global historical optimal solution; iteratively updating the position of the particle; calculating the fitness of each particle and updating the individual historical optimal solution and the global historical optimal solution; calculating the information entropy after updating the position of the particle each time; performing the mutation operation on the particle according to the size of the information entropy; setting the iteration termination condition according to the fitness of the particle, the iteration number and the change rate of the fitness of the particle, and obtaining the optimized particle swarm after the iteration is completed;
[0008] The redundant test case elimination comprises: eliminating the redundant cases in the particle according to the contribution of the optimized particle to the coverage, calculating the information entropy, reserving the redundant test cases in the particle, and outputting the final test case set.
[0009] In the second aspect, the application provides a heuristic test case automatic generation system combined with information entropy, which comprises an initialization unit, an iterative optimization unit and a redundant test case elimination unit.
[0010] The initialization unit is used for initializing the particle swarm and the speed vector of the particle by taking a test case set as a particle, and verifying the initialization result by calculating the information entropy; the test case set comprises a plurality of test cases; the particle swarm comprises a plurality of particles.
[0011] The particle swarm iterative optimization unit is used for: iteratively updating the speed of the particle according to the inertia weight, the learning factor, the random factor, the individual historical optimal solution and the global historical optimal solution; iteratively updating the position of the particle; calculating the fitness of each particle and updating the individual historical optimal solution and the global historical optimal solution; calculating the information entropy after updating the position of the particle each time; performing the mutation operation on the particle according to the size of the information entropy; setting the iteration termination condition according to the fitness of the particle, the iteration number and the change rate of the fitness of the particle, and obtaining the optimized particle swarm after the iteration is completed.
[0012] The redundant test case elimination unit is used for: eliminating the redundant cases in the particle according to the contribution of the optimized particle to the coverage, calculating the information entropy, reserving the redundant test cases in the particle, and outputting the final test case set.
[0013] On the basis of the above technical solution, the application can be further improved as follows.
[0014] Further, the initialization particle swarm comprises:
[0015] defining an input space; the input space comprises a plurality of input parameters, each input parameter represents a dimension, and each input parameter comprises a plurality of intervals; dividing the input space into a plurality of equally spaced intervals;
[0016] Randomly select a value in each interval of the input space to generate several sample points;
[0017] Randomly combine sample points of different dimensions to generate several test cases.
[0018] Further, let the number of sample points and test cases be the first input parameter, the total number of input parameters, the value of the first input parameter in the first test case, the first test case, the first input parameter, the first test case, the first test case, the first test case, the first test case is expressed as:
[0019] ;
[0020] Let the minimum value of the first input parameter, the maximum value of the first input parameter, the value of the first input parameter in the first test case, and the value range of each input parameter is , the random interval index, the number of sample points, then: .
[0021] .
[0022] Further, let represent the first dimension of the velocity vector, a adjustable scale factor, , the first input parameter, representing a uniformly distributed random number, the velocity vector of the particle is expressed as:
[0023] .
[0024] Further, let the inertia weight be , the maximum value of the inertia weight be , the minimum value of the inertia weight be , the current iteration number be , the total iteration number be , the learning factor be and The random factor is and , No. The current position of each particle is The individual optimal solution is The global optimal solution is , For the first The first particle The speed of each iteration For the first The first particle The speed of the next iteration is:
[0025] ;
[0026] The velocity of the updated particle is expressed as:
[0027] .
[0028] Furthermore, let the first... The first particle The position of the next iteration is , No. The first particle The position of the next iteration is , For the first The first particle The velocity of the next iteration, updating the particle's position, is expressed as:
[0029] .
[0030] Furthermore, the particle mutation operation is performed based on the magnitude of information entropy, including: if the information entropy drops to a set threshold, then a set proportion of test cases are randomly selected from the current test case set, and a test case is randomly selected from each test case set to perform a mutation operation on the selected test case; the mutation operation includes randomly modifying input values and adding / deleting operations.
[0031] Furthermore, the iteration termination condition is that the number of iterations reaches the set maximum number of iterations, or the fitness value of the global optimal solution changes by less than a set threshold in a set number of consecutive iterations, or the coverage reaches a preset coverage target value.
[0032] Furthermore, let the first... The test cases are Test cases The set is represented as Test cases The contribution to coverage is The fitness function of the particle is , test case set is , denotes the coverage after test case is removed from test case set , denotes the path coverage of test case set , denotes the branch coverage of test case set, and are adjustable weight parameters, then the fitness function of the particle is:
[0033] ;
[0034] The contribution of test case to the coverage is expressed as: .
[0035] The beneficial effects of the present application are:
[0036] (1) The present application combines information entropy to realize diversity optimization of test case set: by introducing normalized information entropy as an important evaluation index of test case set diversity, the difference and diversity of test case set are judged by information entropy, and the problems of uneven distribution of test case or insufficient diversity are avoided; in the particle initialization and iteration process, the information entropy of the test case set is dynamically adjusted to ensure the breadth of the coverage range and the uniformity of the test case distribution;
[0037] (2) The present application introduces particle swarm algorithm into the field of automatic generation of test cases, and optimizes it, defines the test case set as a particle, and realizes the comprehensive optimization of path coverage and branch coverage;
[0038] (3) The present application proposes a redundant test case elimination mechanism: the present application proposes a redundant test case elimination algorithm based on coverage contribution, calculates the incremental contribution of test case to coverage, and eliminates test cases with no contribution or low contribution; dynamically maintain information entropy during the elimination process to ensure that the removal of redundancy does not significantly reduce the diversity of the test case set, so as to balance the coverage and test efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0039] Figure 1 is the principle diagram of the heuristic test case automatic generation method combined with information entropy provided for embodiment 1 of the present application;
[0040] Figure 2 is the flowchart of the heuristic test case automatic generation method combined with information entropy;
[0041] Figure 3 is the principle diagram of the heuristic test case automatic generation system combined with information entropy provided for embodiment 2 of the present application. Detailed Implementation
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0043] Example 1
[0044] As an example, see the attached document. Figure 1 As shown, in order to solve the above technical problems, this embodiment provides a heuristic test case automatic generation method that combines information entropy, including initialization, particle swarm iterative optimization and redundant test case elimination;
[0045] Initialization includes: treating a test case set as a particle, initializing the particle swarm and the particle's velocity vector, calculating the information entropy to verify the initialization result; a test case set contains several test cases; a particle swarm contains several particles;
[0046] Particle swarm optimization includes: iteratively updating the particle velocity based on inertia weight, learning factor, random factor, individual historical best solution, and global historical best solution; iteratively updating the particle position; calculating the fitness of each particle and updating the individual historical best solution and global historical best solution; calculating the information entropy after each particle position update; performing mutation operations on particles based on the magnitude of the information entropy; setting the iteration termination condition based on the particle fitness, the number of iterations, and the rate of change of the particle fitness; and obtaining the optimized particle swarm after the iteration is completed.
[0047] Redundant test case removal includes: removing redundant test cases from particles based on the contribution of optimized particles to coverage, calculating information entropy, retaining redundant test cases from particles, and outputting the final test case set.
[0048] As attached Figure 2 The flowchart shown is a heuristic test case automatic generation method that combines information entropy.
[0049] Optionally, initializing the particle swarm includes:
[0050] Define the input space; the input space contains several input parameters, each input parameter represents a dimension, and each input parameter contains several intervals; divide the input space into several equally spaced intervals;
[0051] Randomly select a value in each interval of the input space to generate several sample points;
[0052] Randomly combine sample points from different dimensions to generate several test cases.
[0053] After initializing the particle swarm, the information entropy is calculated to verify the initialization result. If the information entropy is less than the set threshold, the diversity of the test case set is insufficient, and the test case set is re-initialized to ensure that the particle swarm has high diversity and avoid getting stuck in local optima during the initialization phase.
[0054] Optionally, set to the number of sample points and test cases. For the first One input parameter, This represents the total number of input parameters. In the first The first test case The value of each input parameter, For the first The nth test case, then the nth Each test case is represented as:
[0055] ;
[0056] set up For the first The minimum value of each input parameter. For the first The maximum value of the input parameters. In the first The first test case The values of each input parameter are given, and the range of values for each input parameter is given. , For random range indexes, The number of sample points. ,but:
[0057] .
[0058] As an optional implementation, let the number of particles be... , These are empirical parameters. The value ranges from 5 to 10. Given the sum of the number of paths and the number of branches, the optimal number of particles is:
[0059] .
[0060] Optional, set The first part represents the velocity vector. dimensional components, It is an adjustable scaling factor. , For the first One input parameter, A random number uniformly distributed is generated, and the velocity vector of the particle is represented as:
[0061] .
[0062] The adjustable scale factor controls the magnitude of the velocity, and a larger velocity allows the particle to explore the search space widely, while a smaller velocity enables the particle to search in a local area finely. By adjusting the value of the adjustable scale factor, the balance between exploration and exploitation can be controlled.
[0063] By the optimized particle swarm algorithm, the position and velocity of the particle are iteratively updated, and a high-quality test case set can be obtained.
[0064] Optionally, the inertia weight is set as , the maximum value of the inertia weight is , the minimum value of the inertia weight is , the current iteration number is , the total iteration number is , the learning factor is and , the random factor is and , the current position of the th particle is , the individual optimal solution is , the global optimal solution is , , the velocity of the th particle in the th iteration is , the velocity of the th particle in the th iteration is
[0065] ;
[0066] The velocity of the particle is updated, and is represented as:
[0067] .
[0068] The inertia weight controls the search ability of the particle, and the global search ability is strong when it is larger, and the local search ability is strong when it is smaller. By dynamically adjusting the inertia weight, the inertia weight changes from large to small with the change of the iteration number, realizing the change from strong global search ability to strong local search ability.
[0069] Generally, the learning factor is initialized as , , , the influence of the individual historical optimal solution on the velocity is represented as , and the influence of the global historical optimal solution on the velocity is represented as . A random value is generated each iteration and , for introducing diversity and exploration ability, combined with learning factors, to realize the update of the velocity and position of particles. Generally, and , the value range of which is: The individual optimal solution represents the historical optimal solution of the current particle, and the global optimal solution represents the best fitness solution among all particles.
[0070] Optionally, the position of the i-th particle in the j-th iteration is set as xi j, the position of the i-th particle in the j-th iteration is set as xi j, the velocity of the i-th particle in the j-th iteration is set as vi j, and the position of the i-th particle is updated, which is represented as: ,
[0071]
[0072] Optionally, the mutation operation is performed on the particles according to the size of the information entropy, including: if the information entropy decreases to a set threshold, a set proportion of test cases in the total number of test cases in the current test case set is randomly selected, and a test case is randomly selected in each test case set, and the selected test case is subjected to a mutation operation; the mutation operation includes randomly modifying the input value and the addition and deletion operation.
[0073] Optionally, the iteration termination condition is that the number of iterations reaches a set maximum number of iterations, or the fitness value of the global optimal solution changes by less than a set threshold in a continuous set number of iterations, or the coverage rate reaches a preset coverage rate target value.
[0074] The preset coverage rate target value is, for example, the fitness value reaches 95% or more.
[0075] Optionally, the i-th test case is set as xi, the set of test cases xi is represented as xi, and the contribution of the test case xi to the coverage rate is set as xi. , branch coverage of a test case set, and is an adjustable weight parameter, then the fitness function of the particle is:
[0076] ;
[0077] test case The contribution of a test case to coverage is represented as: .
[0078] Path coverage is the ratio of covered paths to total paths. The total paths are extracted using static analysis tools to generate the control flow graph of the program. The program is instrumented, and the test case set is executed to record the actual paths covered, and the covered paths are obtained.
[0079] Branch coverage is the ratio of covered branches to total branches. Static analysis extracts all conditional branches in the program to obtain the total number of branches. The program is instrumented, and the test case set is executed to record the actual paths covered, and the covered branches are obtained.
[0080] The coverage of the test case set is calculated, for example, by bitmap representation, including the following steps:
[0081] Define two bitmaps: let the path bitmap be , the length of the path bitmap is the total number of paths, and the total number of paths is , indicates the state of the th path being covered, indicates the state of the th path being covered, ; let the branch bitmap be , the length of the branch bitmap is the total number of branches, and the total number of branches is , indicates the state of the th path being covered, indicates the state of the th path being covered, ; and are initialized to ;
[0082] Instrument to generate coverage information: modify the value in the corresponding bitmap to 1 for each covered path, and modify the value in the corresponding bitmap to -1 for each covered branch;
[0083] Execute the instrumented program for each test case, collect the coverage of paths and branches, and update the bitmaps. If the covered path , then the path bitmap , and if the covered branch , then branch bitmap ;
[0084] The path coverage and branch coverage are calculated:
[0085] ;
[0086] .
[0087] The set threshold of the contribution of coverage is If is less than the set threshold (such as 0.1%), the redundant test case is removed , the next test case is recalculated until the contribution of the test case to the coverage is greater than or equal to the set threshold; after removing the redundant test case, the information entropy of the particle is calculated, if the information entropy decreases by more than a set value, some redundant test cases are retained to maintain the diversity of the particle swarm, and finally a test case set with as few test cases as possible but as high coverage as possible can be output.
[0088] The present application has the following advantages:
[0089] (1) The present application combines information entropy to realize diversity optimization of the test case set: by introducing normalized information entropy as an important evaluation index of the diversity of the test case set, the difference and diversity of the test case set are judged by information entropy, and the problems of uneven distribution of test cases or insufficient diversity are avoided; in the particle initialization and iteration process, the information entropy of the test case set is dynamically adjusted to ensure the breadth of the coverage range and the uniformity of the test case distribution;
[0090] (2) The present application introduces the particle swarm algorithm into the field of automatic generation of test cases, and optimizes it, defines the test case set as a particle, and realizes the comprehensive optimization of path coverage and branch coverage;
[0091] (3) The present application proposes a redundant test case removal mechanism: the present application proposes a redundant test case removal algorithm based on coverage contribution, by calculating the incremental contribution of the test case to the coverage, the test cases with no contribution or low contribution are removed; in the removal process, the information entropy is dynamically maintained to ensure that the removal of redundancy does not cause a significant decrease in the diversity of the test case set, so as to balance the coverage and test efficiency.
[0092] Example 2
[0093] Based on the same principle as the method shown in Example 1 of the present application, as shown in the accompanying Figure 3 , the present application provides a heuristic test case automatic generation system combined with information entropy in the embodiment, which includes an initialization unit, an iterative optimization unit and a redundant test case removal unit;
[0094] an initialization unit, configured to initialize a particle swarm and a velocity vector of a particle by taking a test case set as a particle, and to calculate information entropy to verify an initialization result; the test case set contains a plurality of test cases; the particle swarm contains a plurality of particles;
[0095] a particle swarm iterative optimization unit, configured to: iteratively update a velocity of a particle according to an inertia weight, a learning factor, a random factor, an individual historical optimal solution and a global historical optimal solution; iteratively update a position of the particle; calculate an adaptability of each particle and update the individual historical optimal solution and the global historical optimal solution; calculate information entropy after each update of the position of the particle; perform a mutation operation on the particle according to a size of the information entropy; set an iteration termination condition according to the adaptability of the particle, an iteration number and a change rate of the adaptability of the particle, and obtain an optimized particle swarm after the iteration is completed;
[0096] a redundant test case elimination unit, configured to eliminate a redundant test case in a particle according to a contribution of the optimized particle to coverage, to calculate information entropy, to retain the redundant test case in the particle, and to output a final test case set.
[0097] Optionally, the initialization of the particle swarm includes:
[0098] defining an input space; the input space contains a plurality of input parameters, each input parameter represents a dimension, and each input parameter contains a plurality of intervals; dividing the input space into a plurality of equally spaced intervals;
[0099] randomly selecting a value in each interval of the input space to generate a plurality of sample points;
[0100] randomly combining sample points of different dimensions to generate a plurality of test cases.
[0101] Optionally, the number of the sample points and the test cases is set as the i th input parameter is the total number of the input parameters is the value of the i th input parameter in the j th test case is the i th test case is
[0102] ;
[0103] let the minimum value of the i th input parameter be The maximum value of the input parameters. In the first The first test case The values of each input parameter are given, and the range of values for each input parameter is given. , For random range indexes, The number of sample points. ,but:
[0104] .
[0105] Optional, set The first part represents the velocity vector. dimensional components, It is an adjustable scaling factor. , For the first One input parameter, This represents generating a uniformly distributed random number, and the particle's velocity vector is represented as:
[0106] .
[0107] Optionally, let the inertia weight be... The maximum value of the inertia weight is The minimum value of the inertia weight is The current iteration number is The total number of iterations is The learning factor is and The random factor is and , No. The current position of each particle is The individual optimal solution is The global optimal solution is , For the first The first particle The speed of the next iteration For the first The first particle The speed of the next iteration is:
[0108] ;
[0109] The velocity of the updated particle is expressed as:
[0110] .
[0111] Optionally, let the first The first particle The position of the next iteration is , No. the position of the particle in the i-th iteration , the velocity of the particle in the i-th iteration the position of the particle in the i-th iteration is updated, denoted as:
[0112]
[0113] Optionally, the particle is subjected to mutation operation according to the size of the information entropy, including: if the information entropy decreases to a set threshold, a set proportion of test cases in the total number of test cases in the current test case set is randomly selected, and one test case in each test case set is randomly selected, and the selected test cases are subjected to mutation operation; the mutation operation includes random modification of input values and addition and deletion operations.
[0114] Optionally, the iteration termination condition is that the number of iterations reaches a set maximum number of iterations, or the fitness value of the global optimal solution changes by less than a set threshold in continuous iterations for a set number of times, or the coverage rate reaches a preset coverage rate target value.
[0115] Optionally, the i-th test case is denoted as , the set of test cases is denoted as , the contribution of the test case to the coverage rate is denoted as , the fitness function of the particle is denoted as , the test case set is denoted as , , the path coverage rate of the test case set , denotes the coverage rate after removing the test case from the test case set , denotes the path coverage rate of the test case set , denotes the branch coverage rate of the test case set, and are adjustable weight parameters, , the fitness function of the particle is:
[0116] ;
[0117] The contribution of the test case to the coverage rate is denoted as: .
[0118] The above merely describes the preferred embodiments of the present application, and is not used to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A heuristic test case automatic generation method combined with information entropy, characterized in that, The initialization, the particle swarm iterative optimization and the redundant test case elimination are included. The initialization includes: taking a test case set as a particle, initializing the particle swarm and the velocity vector of the particle, and calculating information entropy to verify the initialization result; the test case set includes a plurality of test cases; the particle swarm includes a plurality of particles. The particle swarm iteration optimization comprises: iteratively updating the speed of the particle according to an inertia weight, a learning factor, a random factor, an individual historical optimal solution and a global historical optimal solution; iteratively updating the position of the particle; and calculating the fitness of each particle and updating the individual historical optimal solution and the global historical optimal solution, comprising: setting the first test case as , the set of test cases is represented as , the contribution of the test case to the coverage is , the fitness function of the particle is , the test case set is , , represents the coverage after removing the test case from the test case set , represents the path coverage of the test case set , represents the branch coverage of the test case set, and are adjustable weight parameters, , the fitness function of the particle is: ; the contribution of the test case to the coverage is represented as: ; the particle is subjected to a mutation operation according to the size of the information entropy; an iteration termination condition is set according to the fitness of the particle, the number of iterations and the change rate of the fitness of the particle, and the optimized particle swarm is obtained after the iteration is completed. The redundant test case elimination includes: eliminating the redundant cases in the particle according to the contribution of the optimized particle to the coverage, eliminating the redundant test case if the contribution of the test case to the coverage is less than a set threshold, recalculating the next test case until the contribution of the test case to the coverage is greater than or equal to the set threshold; calculating the information entropy after updating the position of the particle each time; and reserving the redundant test cases in the particle and outputting the final test case set.
2. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 1 wherein, The initialization of the particle swarm includes: defining an input space; the input space includes a plurality of input parameters, each input parameter representing a dimension, and each input parameter including a plurality of intervals; and dividing the input space into a plurality of equally spaced intervals; randomly selecting a value in each interval of the input space to generate a plurality of sample points; randomly combining the sample points of different dimensions to generate a plurality of test cases.
3. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 2 wherein, set up The number of sample points and test cases. For the first One input parameter, This represents the total number of input parameters. In the first The first test case The value of each input parameter, For the first The nth test case, then the nth Each test case is represented as: ; Let be the minimum value of the th input parameter, be the maximum value of the th input parameter, be the value of the th input parameter in the th test case, and the value range of each input parameter is , be the random interval index, be the number of sample points, then: 。 4. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 1 wherein, set up The first velocity vector represents the velocity vector. dimensional components, It is an adjustable scaling factor. , For the first One input parameter, This represents generating a uniformly distributed random number, and the particle's velocity vector is represented as: 。 5. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 1 wherein, Let the inertia weight be... The maximum value of the inertia weight is The minimum value of the inertia weight is The current iteration number is The total number of iterations is The learning factor is and The random factor is and , No. The current position of each particle is The individual optimal solution is The global optimal solution is , For the first The first particle The speed of the next iteration For the first The first particle The speed of the next iteration is: ; The velocity of the particle is updated and is expressed as: 。 6. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 1 wherein, Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be , Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be Let the position of the i-th particle at the j-th iteration be 。 7. The method of claim 1, wherein the heuristic test case generation based on information entropy is characterized by, The particle is subjected to a mutation operation according to the size of the information entropy, including: if the information entropy decreases to a set threshold, randomly selecting a set proportion of test cases in the current test case set, and randomly selecting a test case in each test case set, and subjecting the selected test cases to a mutation operation; the mutation operation includes randomly modifying the input value and the addition and deletion operation.
8. The method for automatic generation of test cases using heuristics incorporating information entropy as claimed in claim 1 wherein, The iteration termination condition is that the iteration number reaches a set maximum iteration number, or the fitness value of the global optimal solution changes by less than a set threshold in continuous iteration for a set number of times, or the coverage reaches a preset coverage target value.
9. A system for generating heuristic test cases based on information entropy according to claim 1, characterized in that, The initialization unit, the iterative optimization unit and the redundant test case elimination unit are included. The initialization unit is configured to take a test case set as a particle, initialize the particle swarm and the velocity vector of the particle, and calculate information entropy to verify the initialization result; the test case set includes a plurality of test cases; and the particle swarm includes a plurality of particles. The particle swarm iterative optimization unit is configured to: iteratively update the velocity of the particle according to the inertia weight, the learning factor, the random factor, the individual historical optimal solution and the global historical optimal solution; and iteratively update the position of the particle. The fitness of each particle is calculated and the individual historical optimal solution and the global historical optimal solution are updated, including: setting the first test case as , , the set of test cases is expressed as , the contribution of test case to the coverage is , the fitness function of the particle is , the test case set is , represents the coverage after removing test case from the test case set , represents the path coverage of the test case set , represents the branch coverage of the test case set, and are adjustable weight parameters, , then the fitness function of the particle is: ; the contribution of test case to the coverage is expressed as: ; the particles are subjected to mutation operation according to the size of information entropy; the iteration termination condition is set according to the fitness of the particle, the iteration number and the change rate of the fitness of the particle, and the optimized particle swarm is obtained after the iteration is completed; The redundant test case elimination unit is configured to: eliminate the redundant cases in the particle according to the contribution of the optimized particle to the coverage, eliminate the redundant test case if the contribution of the test case to the coverage is less than a set threshold, recalculating the next test case until the contribution of the test case to the coverage is greater than or equal to the set threshold; calculate the information entropy after updating the position of the particle each time; and reserve the redundant test cases in the particle and output the final test case set.
Citation Information
Patent Citations
Character selection method based on particle swarm optimization algorithm
CN105718943A
Test case generation method based on information entropy particle swarm optimization algorithm
CN108763069A