Test case combination generation method, device, system, equipment and medium
By introducing a niche particle swarm optimization algorithm with ring topology and similarity measurement in the generation of combined test cases, the particle fitness is dynamically adjusted, and the problem of insufficient control of the scale of the test case set is solved, the testing efficiency and quality are improved, and the cost is reduced.
Patent Information
- Application Number
- CN202510565217.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2045-04-30
AI Technical Summary
The existing combined test case generation methods have problems of low testing efficiency and poor testing quality. This is mainly due to the lack of effective control of the scale of the test case set, which leads to redundant test cases increasing computing resources, storage space and execution time, affecting test efficiency and quality.
A niche particle swarm optimization algorithm using a ring topological structure is used to adjust particle fitness dynamically through similarity measurement and dynamically adjust particle fitness, optimize the test case generation process, introduce distance and coverage radius measurements, dynamically adjust particle fitness, and generate global or approximately global optimal solutions.
Effectively control the scale of test case sets, improve the efficiency and quality of test case generation, reduce test costs, enhance global search capabilities, avoid premature convergence, and ensure coverage.
Smart Images

Figure CN120492333A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of combined test case generation, and in particular to a test case combination generation method, apparatus, system, equipment and medium. Background Art
[0002] Existing combinatorial test case generation methods, such as particle swarm optimization (PSO) and genetic algorithms (GA), rely on heuristic optimization methods and possess strong global search capabilities, enabling them to find high-coverage test case sets within a large input space. However, these algorithms typically focus on improving coverage and fail to effectively control the size of the test case set. Due to this lack of size control, test case sets often contain redundant test cases, resulting in test case sizes exceeding actual requirements. This not only increases computing resources, storage space, and execution time, but also increases testing costs and impacts test efficiency. This can lead to the inability to fully execute all test cases within a limited test cycle, thus compromising test quality. Summary of the Invention
[0003] The purpose of the embodiments of the present application is to provide a test case combination generation method, device, system, equipment and medium to solve the problems of low test efficiency and poor test quality of existing combination test case generation methods.
[0004] In a first aspect, an embodiment of the present application provides a test case combination generation method, which is applied to an automated testing platform, comprising:
[0005] Initialize particles and set the structure between particles to a ring topology; each particle represents a test case;
[0006] Based on the set similarity measurement rules, the similarity between particles is measured and the fitness of particles is dynamically adjusted;
[0007] Iterate the fitness according to the set update rules;
[0008] When the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the results are output; the output results include the global optimal solution or the approximate global optimal solution, and the output results are used as newly generated test cases.
[0009] In the above implementation process, the embodiment of the present application initializes particles and sets the structure between particles to a ring topology structure; wherein each particle represents a test case; based on the set similarity measurement rule, the similarity between particles is measured, and the fitness of the particles is dynamically adjusted; the fitness is iterated according to the set update rule; when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the result is output; wherein the output result includes a global optimal solution or an approximate global optimal solution, and the output result is used as a newly generated test case; by operating the automated testing platform, based on the ring topology structure and the similarity measurement rule, the fitness of the particles is dynamically adjusted, the fitness is dynamically adjusted, and a test case combination is generated, thereby improving the efficiency and quality of test case generation.
[0010] Furthermore, the dynamic adjustment of the fitness of the particles includes:
[0011] The fitness of a particle is weightedly modified based on its minimum distance from other particles in the population and its coverage radius;
[0012] When the minimum distance of a particle is large and the coverage radius is small, the fitness of the particle is improved;
[0013] When the minimum distance is small or the coverage radius is large, the fitness of the particle is reduced.
[0014] In the above implementation process, the fitness of the particles is dynamically adjusted so that the fitness can be adjusted later to generate test case combinations.
[0015] Furthermore, the initialization particles include:
[0016] Initialize the position and velocity of the particles; each particle represents a test case, and the position of each particle corresponds to a parameter value combination of a test case;
[0017] Initialize the historical optimal solution of each particle as the initial position of the particle, and initialize the best solution of all particles as the global optimal solution;
[0018] Sort all particles by fitness and select the current best individual as the first leader particle;
[0019] With the leader particle as the center, several particles are selected within a preset radius based on cosine distance to form a small habitat together with the leader particle;
[0020] Remove all particles in the niche from the main population;
[0021] Repeat the operation to continue selecting new leader particles from the remaining particles and dividing the niche until all particles are allocated;
[0022] The particle with the best fitness in each niche is set as the corresponding local optimal solution.
[0023] In the above implementation process, the particle swarm is effectively initialized to prepare for subsequent iterative optimization.
[0024] Furthermore, the similarity between particles is measured based on the set similarity measurement rule, including:
[0025] The distance is used to measure the difference between any two test cases in the coverage array. The larger the minimum distance, the more obvious the difference between the test cases.
[0026] The minimum distance is calculated as follows:
[0027]
[0028] Where C is a coverage array containing a set of test cases; x and y are any two test cases in the coverage array; ||xy|| represents the distance metric between the two;
[0029] The coverage radius is used to measure the coverage capability of the covering array in the entire test space. The larger the coverage radius, the more test cases the covering array can cover.
[0030] The calculation formula for coverage radius is as follows:
[0031]
[0032] Where g is an ideal point in the test space; x is any test case in the coverage array.
[0033] In the above implementation process, distance and coverage radius are used as important indicators to evaluate particle fitness to optimize the generation of test cases and ensure efficient test coverage with a smaller number of test cases.
[0034] Furthermore, the dynamic adjustment of the fitness of the particles includes:
[0035] Adjust the fitness of particle calculations based on minimum distance and coverage radius:
[0036] Score(C)=Coverage(C)+α·d(C)-β·ρ(C);
[0037] Among them, Coverage(C) is the original fitness, d(C) is the minimum distance, ρ(C) is the coverage radius; α and β are set constants.
[0038] In the above implementation process, fitness reflects the number of combinations covered by test cases, and a larger value indicates better coverage.
[0039] Furthermore, the iterating of the fitness according to the set update rule includes:
[0040] If the current fitness of the particle is better than the fitness of its historical optimal solution, the historical optimal solution is updated to the current position of the particle;
[0041] Calculate the fitness of each particle in each niche and compare it with the local optimal solution in the current niche; if the calculated fitness of the particle in the niche is better than the local optimal solution in the current niche, update the local optimal solution in the current niche to the position of the particle in the calculated niche;
[0042] If the current fitness of the particle is better than the fitness of its global optimal solution, the global optimal solution is updated to the current position of the particle;
[0043] Update the particle's velocity:
[0044] V i (t+1)=ωV i (t)+c1γ1(pBest i (t)-X i (t))+c2γ2(Swarms localbest -X i (t));
[0045] Update the particle's position:
[0046] X i (t+1)=X i (t)+V i (t+1);
[0047] Among them, X i (t) is the position vector, X i (t) = [x i1 (t),x i2 (t),…,x id (t)];
[0048] Among them, V i (t) is the velocity vector, V i (t)=[v i1 (t),v i2 (t),…,v id (t)];
[0049] Among them, X i (t) and V i (t) represent the position and velocity of the particle at time t, X i (t+1) and V i(t+1) are the updated position and velocity respectively; ω is the inertia weight factor; c1 and c2 are acceleration factors greater than zero; y1,y2∈[0,1,0];
[0050] When updating the particle's position, a bounds check is performed to ensure that the particle's position is within the domain.
[0051] In the above implementation process, by adaptively adjusting the subgroup, we ensure that particles can fully explore the entire search space and avoid focusing on the local optimal solution too early. This not only enhances the global search capability, but also improves the diversity and coverage of the test case set, thereby improving test quality and efficiency.
[0052] In a second aspect, an embodiment of the present application provides a test case combination generation device integrated into an automated testing platform, comprising:
[0053] The particle initialization module is used to initialize particles and set the structure between particles to a ring topology; each particle represents a test case;
[0054] The particle measurement module is used to measure the similarity between particles based on the set similarity measurement rules and dynamically adjust the fitness of particles;
[0055] Iterative processing module, used to iterate the fitness according to the set update rules;
[0056] The use case output module is used to stop the iteration and output the results when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered; the output results include the global optimal solution or the approximate global optimal solution, and the output results are used as the newly generated test cases.
[0057] In a third aspect, an embodiment of the present application provides a test case combination generation system, the test case combination generation system including an automated testing platform, the automated testing platform including: a test case combination generation module, a case operation module, a visualization module, and a test case combination generation device as described above connected to the test case combination generation module;
[0058] The test case combination generation module is used for parameter input and algorithm selection; the case operation module is used for parameter modification and parameter deletion; and the visualization module is used for displaying test results and displaying chart analysis.
[0059] In a fourth aspect, an embodiment of the present application provides an electronic device, including:
[0060] A processor, a memory and a bus, wherein the processor is connected to the memory via the bus, and the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, they are used to implement the test case combination generation method as described above.
[0061] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a server, the test case combination generation method as described above is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0063] Figure 1 A flow chart of a test case combination generation method provided in an embodiment of the present application;
[0064] Figure 2 This is a schematic diagram of the structure of a test case combination generating device provided by an embodiment of the present application;
[0065] Figure 3 This is a schematic diagram of the functional structure of a software system of an automated testing platform provided in an embodiment of the present application;
[0066] Figure 4 This is a schematic diagram of the overall software architecture design structure of an automated testing platform provided in an embodiment of the present application;
[0067] Figure 5 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0068] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0069] It should be noted that similar reference numerals and letters represent similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and should not be understood as indicating or implying relative importance.
[0070] Current mainstream combinatorial test case generation algorithms, particularly the particle swarm optimization (PSO) algorithm, are an important technique based on heuristic optimization methods. PSO was first proposed to simulate the collaborative behavior of flocks of birds and schools of fish in their search for food, aiming to solve optimization problems. PSO updates the positions of particles to find the optimal solution, making it suitable for combinatorial testing. This algorithm possesses strong search capabilities and is capable of finding high-coverage test case sets in large input spaces.
[0071] However, the PSO search objective typically focuses on improving coverage, but lacks sufficient control over the size of the generated test case set, which can easily lead to the generation of redundant test cases. To address this, the QPSO algorithm was first introduced. By quantizing particle positions, it improves global search capabilities and reduces the frequency of local optima. Subsequently, QPSO was applied to the generation of variable-strength coverage tables for combinatorial testing. The integration of Lamarckian and Baldwin learning methods enhanced the algorithm's performance, enabling it to generate coverage tables with a coverage strength of up to 15.
[0072] With the advancement of research, fitness sharing has become another important diversity-preserving technique. This method improves search diversity by adjusting the competitive relationships between individuals, thereby preventing the algorithm from premature convergence. In recent years, the PSO algorithm has spawned many species-based optimization methods, such as subtractive particle swarm optimization and species-based particle swarm optimization. These methods avoid local optimal solutions by introducing adaptive subgroups into the particle swarm.
[0073] In terms of automated platforms for combinatorial test case generation, existing mainstream tools facilitate test case generation and management. In 1992, Bell Labs developed the OATS tool, which uses orthogonal arrays to generate test cases. This mathematical model-based testing approach effectively reduces the number of test cases while ensuring comprehensive coverage of input parameters.
[0074] In addition, a one-dimensional extended greedy strategy (OTAT) was proposed, and the AETG (Automatic Efficient Test Generator) tool was developed based on this strategy. OTAT constructs a test case set through gradual expansion, optimizing generation efficiency while ensuring coverage. The column-by-column expansion strategy (IPO) is another commonly used greedy algorithm that constructs test cases parameter by parameter. Although it is fast, the generated test case set is large. Therefore, improved IPO algorithms such as IPOG and IPOG-D have been integrated into the ACTS test tool to further optimize test case generation.
[0075] In addition to these algorithms, some methods based on mathematical construction are also widely used, such as Testcover, Tconfig and WHITCH tools. These tools use different mathematical models to improve the efficiency and adaptability of test case generation and can meet a variety of different software testing needs.
[0076] In summary, existing combinatorial test case generation algorithms and automation platforms have achieved significant results in improving test efficiency and coverage. However, existing technologies still suffer from issues such as redundant test case generation, insufficient scale control, and low automation, which increase testing costs and execution time. Therefore, effectively controlling test case scale and improving automation while ensuring test coverage remains a challenge in the field of combinatorial testing.
[0077] Based on this, an embodiment of the present application proposes a test case combination generation method to solve the above problems.
[0078] Please see Figure 1 , Figure 1 A flow chart of a test case combination generation method provided in an embodiment of the present application. Figure 1 The test case combination generation method is applied to an automated testing platform, and the method includes:
[0079] 100. Initialize particles and set the structure between particles to a ring topology; each particle represents a test case.
[0080] Specifically, the positions and velocities of the particles are initialized. Each particle represents a test case, and the position of each particle corresponds to a parameter value combination for that test case. The historical optimal solution of each particle is initialized as the particle's initial position, and the best solution among all particles is initialized as the global optimal solution. All particles are sorted by fitness, and the currently optimal individual is selected as the first leader particle. With the leader particle as the center, several particles are selected within a preset radius based on cosine distance to form a microhabitat with the leader particle. All particles within the microhabitat are removed from the main swarm. The above steps are repeated, and new leader particles are selected from the remaining particles and the microhabitats are divided until all particles are assigned. The particle with the best fitness in each microhabitat is set as the corresponding local optimal solution. This effectively initializes the particle swarm and prepares for subsequent iterative optimization.
[0081] 200. Based on the set similarity measurement rules, the similarity between particles is measured and the fitness of particles is dynamically adjusted.
[0082] Optionally, a weighted correction is performed on the fitness of a particle based on its minimum distance from other particles in the population and its coverage radius; when the minimum distance of a particle is large and the coverage radius is small, the fitness of the particle is increased; when the minimum distance is small or the coverage radius is large, the fitness of the particle is reduced. It is understandable that a large minimum distance of a particle means that the minimum distance of the particle is greater than or equal to a set first distance threshold, a small minimum distance of a particle means that the minimum distance of the particle is less than or equal to a set second distance threshold, a small coverage radius of a particle means that the coverage radius of the particle is less than or equal to the set first radius threshold, and a large coverage radius of a particle means that the coverage radius of the particle is greater than or equal to the set second radius threshold.
[0083] Optionally, adjust the fitness of the particle calculation based on the minimum distance and coverage radius:
[0084] Score(C)=Coverage(C)+α·d(C)-β·ρ(C);
[0085] Among them, Coverage(C) is the original fitness, d(C) is the minimum distance, ρ(C) is the coverage radius; α and β are set constants.
[0086] In the above implementation process, fitness reflects the number of combinations covered by test cases, and a larger value indicates better coverage.
[0087] 300. Iterate the fitness according to the set update rules.
[0088] Optionally, if the current fitness of the particle is better than the fitness of its historical optimal solution, the historical optimal solution is updated to the current position of the particle.
[0089] The fitness of each particle in each niche is calculated and compared with the local optimal solution in the current niche. If the fitness of the particle in the calculated niche is better than the local optimal solution in the current niche, the local optimal solution in the current niche is updated to the position of the particle in the calculated niche.
[0090] If the current fitness of the particle is better than the fitness of its global optimal solution, the global optimal solution is updated to the current position of the particle.
[0091] Update the particle's velocity:
[0092] V i (t+1)=ωV i (t)+c1γ1(pBest i (t)-X i (t))+c2γ2(Swarms localbest -X i (t)).
[0093] Update the particle's position:
[0094] X i (t+1)=X i (t)+V i (t+1).
[0095] Among them, X i (t) is the position vector, X i (t) = [x i1 (t),x i2 (t),…,x id (t)].
[0096] Among them, V i (t) is the velocity vector, V i (t)=[v i1 (t),v i2 (t),…,v id (t)].
[0097] Among them, X i (t) and V i (t) represent the position and velocity of the particle at time t, X i (t+1) and V i (t+1) are the updated position and velocity respectively; ω is the inertia weight factor; c1 and c2 are acceleration factors greater than zero; y1,y2∈[0,1,0].
[0098] When updating the particle's position, a bounds check is performed to ensure that the particle's position is within the domain.
[0099] 400. When the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the results are output; wherein the output results include a global optimal solution or an approximate global optimal solution, and the output results are used as a newly generated test case.
[0100] As described above, the embodiment of the present application initializes particles and sets the structure between particles to a ring topology structure; wherein each particle represents a test case; based on the set similarity measurement rule, the similarity between particles is measured, and the fitness of the particles is dynamically adjusted; the fitness is iterated according to the set update rule; when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the result is output; wherein the output result includes a global optimal solution or an approximate global optimal solution, and the output result is used as a newly generated test case; by operating the automated testing platform, based on the ring topology structure and the similarity measurement rule, the fitness of the particles is dynamically adjusted, the fitness is dynamically adjusted, and a test case combination is generated to improve the efficiency and quality of test case generation.
[0101] As mentioned above, in order to address the problems that the test case set generated by the traditional particle swarm algorithm is too large and the traditional niche particle swarm algorithm is prone to premature convergence, the embodiment of the present application introduces distance and coverage radius metrics, and improves the niche particle swarm algorithm by changing the traditional topology structure to a ring topology structure; this method reduces the size of the test case set and improves the efficiency of test case generation, thereby reducing testing costs and improving test quality.
[0102] The improved niche particle swarm algorithm in the embodiment of the present application applies the principle of combinatorial testing: a set of smaller test cases is selected from all possible parameter value combinations to ensure that these test cases can cover all parameter value combinations required by the system.
[0103] Specifically, suppose there is a SUT (System Under Test), which contains n parameters, denoted as C = {c1, c2, ..., c n}, where each parameter c i The value comes from the set V i , set c1 contains a i elements, which is a finite discrete point set, which means that each parameter c1 can take a i discrete values. Use set R to represent the coverage requirement, If {c1,c2}∈R, it means that the interaction between c1 and c2 may cause software failure. In order to cover the a1×a2 value combinations of c1 and c2, multiple n-tuples such as {(v1,v2,…,v n ,)|v1∈V1,v2∈V2,…,v n ∈V n} to test the SUT. In order to simplify the description, it is usually described with the symbol CA(N; t,n,d), which can be abbreviated as CA(N; t,d n ), represents a coverage table, where N is the number of test cases, t represents the coverage strength (the value of t is an integer between 1 and n), n is the number of parameters of the system to be tested, and d is the number of values of each parameter.
[0104] The purpose of introducing the niche algorithm into test case generation is, firstly, to guide the population to explore the solution space in a diverse manner, thereby increasing the likelihood of finding the global optimal solution; secondly, to prevent premature convergence and enhance global search capabilities. Specifically, this is done by introducing a shared function to measure the similarity between individuals and using this function to adjust fitness: when an individual is similar to others, its fitness is penalized; otherwise, it is incentivized. The specific test case combination generation process is as follows:
[0105] Particle initialization. Initialize the particle's position x i (t) and velocity vi (t), where each particle represents a test case. The position of each particle corresponds to a parameter value combination of a test case. The historical optimal solution pbest of each particle i Initialize to the initial position of the particle. Initialize the global optimal solution gbest i , represents the best solution among all particles. Initialize the local optimal solution of the niche Swarms localbest , record the best solution in each niche.
[0106] Distance calculation. The distance measurement method is used to evaluate the similarity between particles and the diversity of the group, helping to maintain the diversity of the group and preventing the particle group from converging to the same solution area. The embodiment of the present application uses the following distance algorithms in the implementation process: Euclidean distance, which calculates the "straight line" distance between two particles and measures the difference between particles in multidimensional space. The formula is Where x and y are the two positions of the particle, and n is the dimension of the particle. Manhattan distance measures the sum of the absolute differences of the particle in each dimension, and the formula is Where x and y are the two positions of the particle, and n is the dimension of the particle. Cosine Similarity calculates the angular similarity between particles to evaluate their similarity and measures the directional differences between particles. The formula is Here, x and y are the two positions of the particle, and n is the dimension of the particle.
[0107] The application of these distance metrics enables the particle swarm to maintain diversity and avoid excessive convergence of the swarm.
[0108] Application of distance. Distance d(C) and coverage radius ρ(C) are used as important metrics for evaluating particle fitness to optimize test case generation and ensure efficient test coverage with a small number of test cases. By measuring the distance between particles and the test cases in the coverage array, as well as the coverage radius, the algorithm can dynamically adjust the search direction of the particle swarm, rewarding particles with relatively long distances and large coverage radii, and covering test cases in the array, while penalizing particles with the opposite distances, thereby optimizing the size and quality of the test case set.
[0109] Distance measures the degree of difference between any two test cases in the coverage array. The larger the minimum distance, the more obvious the differences between the test cases, which means that the test cases can cover more different defects, thereby enhancing the comprehensiveness of the test. The minimum distance is calculated as follows: Where: C is the coverage array containing the test case set; x and y are any two test cases in the coverage array; ||xy|| represents the distance metric between the two.
[0110] The coverage radius measures the coverage capability of the covering array in the entire test space. The larger the coverage radius, the more test cases the covering array can cover, thereby improving the comprehensiveness and efficiency of the test. Its calculation formula is as follows: Where: g is an ideal point in the test space, usually the optimal solution covering all possible test scenarios; x is any test case in the coverage array.
[0111] Fitness calculation. The fitness value measures the coverage effectiveness of the test case in the combination coverage state table. Initialize the fitness value to 0, then iterate over all parameter value combinations in lexicographic order. For each combination, calculate its position in the state table. If the value at that position is 1, increase the fitness value by 1. Ultimately, the fitness value reflects the number of combinations covered by the test case, with larger values indicating better coverage.
[0112] Adjust the fitness of particle calculations based on minimum distance and coverage radius:
[0113] Score(C)=Coverage(C)+α·d(C)-β·ρ(C);
[0114] Among them, Coverage(C) is the original fitness, d(C) is the minimum distance, ρ(C) is the coverage radius; α and β are set constants.
[0115] Combined coverage state table CA(N; t,n,1) or CA(N; t,1 n ) is an N×n matrix structure with a range size of l. Any N×t submatrix in the matrix can contain all permutations of size t on the range l. Among them, N represents the number of test cases; t represents the test strength; n represents the degree, that is, the number of factors in the system; l represents the order, that is, the number of values of each factor. For example, the SUT in the combination coverage state table can be represented as CA(9;2,4,3) or CA(9;2,3 4 ). N can also be omitted. In addition, a covering array with the minimum number of rows is considered the optimal covering array, and the minimum number of rows it contains is named the Covering Array Number (CAN).
[0116] Update the historical optimal solution (pbest). If the particle's current fitness (x i ) is better than the fitness of its historical optimal solution (pbest i), then update the historical optimal solution pbest i is the current particle's position x.
[0117] Update local optimal solution (Swarms localbest ). For each niche, calculate the fitness of each particle and compare it with the optimal solution Swarms in the current niche. localbest If the particle fitness is better, the local optimal solution of the niche is updated.
[0118] Update the global optimal solution (gbest). If the particle's current fitness (x i ) is better than the fitness of its historical optimal solution, Fitness(gbest), then the global optimal solution gbest is updated to the position of the current particle.
[0119] Speed and position update. Update the speed of the particle:
[0120] V i (t+1)=ωV i (t)+c1γ1(pBest i (t)-X i (t))+c2γ2(Swarms localbest -X i (t));
[0121] Update the particle's position:
[0122] X i (t+1)=X i (t)+V i (t+1);
[0123] Among them, X i (t) is the position vector, X i (t) = [x i1 (t),x i2 (t),…,x id (t)];
[0124] Among them, V i (t) is the velocity vector, V i (t)=[v i1 (t),v i2 (t),…,v id (t)];
[0125] Among them, X i (t) and V i (t) represent the position and velocity of the particle at time t, X i (t+1) and V i(t+1) are the updated position and velocity respectively; ω is the inertia weight factor; c1 and c2 are acceleration factors greater than zero; y1,y2∈[0,1,0]; when updating the position of the particle, a boundary check is performed to ensure that the particle position is within the domain of definition.
[0126] Topology. A ring topology is used, in which each particle exchanges information only with its immediate and immediate neighbors. This ring topology effectively increases the diversity of the population, preventing particles from becoming overly dependent on other particles and thus preventing premature convergence.
[0127] Stop condition: The algorithm stops when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered.
[0128] Output test cases. The final output results include the global optimal solution or the approximate global optimal solution as the optimal test case combination.
[0129] The above steps are not to be performed in a strict order as described in the numbers, but should be understood as an overall solution.
[0130] In the second aspect, based on the above embodiments, Figure 2 This is a schematic diagram of the structure of a test case combination generation device provided in an embodiment of the present application. Figure 2 The test case combination generation device provided in this embodiment is integrated into the automated testing platform, and specifically includes: a particle initialization module 201, a particle measurement module 202, an iterative processing module 203 and a use case output module 204.
[0131] Among them, the particle initialization module 201 is used to initialize particles and set the structure between particles to a ring topology structure; wherein each particle represents a test case; the particle measurement module 202 is used to measure the similarity between particles based on the set similarity measurement rules, and dynamically adjust the fitness of the particles; the iterative processing module 203 is used to iterate the fitness according to the set update rules; the use case output module 204 is used to stop the iteration and output the result when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered; wherein the output result includes the global optimal solution or the approximate global optimal solution, and the output result is used as the newly generated test case.
[0132] As described above, the embodiment of the present application initializes particles and sets the structure between particles to a ring topology structure; wherein each particle represents a test case; based on the set similarity measurement rule, the similarity between particles is measured, and the fitness of the particles is dynamically adjusted; the fitness is iterated according to the set update rule; when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the result is output; wherein the output result includes a global optimal solution or an approximate global optimal solution, and the output result is used as a newly generated test case; by operating the automated testing platform, based on the ring topology structure and the similarity measurement rule, the fitness of the particles is dynamically adjusted, the fitness is dynamically adjusted, and a test case combination is generated to improve the efficiency and quality of test case generation.
[0133] The embodiment of the present application is based on an improved niche particle swarm optimization (PSO) algorithm, which improves the efficiency and quality of test case generation by optimizing population distribution, introducing a distance measurement mechanism and a dynamic search strategy with a ring topology. The niche mechanism effectively prevents excessive concentration of individuals and reduces redundant test cases. The distance measurement strategy calculates the similarity between test cases, dynamically adjusts the population distribution, improves coverage and optimizes scale. The search strategy enhances global exploration in the early stage and refines local search in the later stage to ensure that the generated test cases are both comprehensive and streamlined in scale. In addition, the algorithm can automatically adjust the inertia weight according to the characteristics of the test data, improve search stability, avoid meaningless redundancy, and reduce testing costs.
[0134] The test case combination generation device provided in the embodiment of the present application can be used to execute the test case combination generation method provided in the above embodiment, and has corresponding functions and beneficial effects.
[0135] In a third aspect, an embodiment of the present application provides a test case combination generation system. In the embodiment of the present application, the test case combination generation system includes an automated testing platform, and the automated testing platform includes: a test case combination generation module, a case operation module, a visualization module, and a test case combination generation device as described above, which is connected to the test case combination generation module; the test case combination generation module is used for parameter input and algorithm selection; the case operation module is used for parameter modification and parameter deletion, and the visualization module is used to display test results and display chart analysis.
[0136] Optionally, an interface testing module is also included for test case modeling and interface testing.
[0137] The automated testing platform (tool) is developed using Vue3 and Electron on the front end, supporting cross-platform use across web and desktop applications. The back end uses Node.js to build services and store data in a MySQL database. The software displays generated test case suites and connects to the interface testing system to automatically execute interface tests and verify their correctness and performance. The tool also provides data analysis and visualization charts to help users evaluate test coverage and performance, improving testing efficiency.
[0138] For example, the overall architecture is as follows Figure 3 As shown, the front-end is written in Vue3 and Electron, with a Chromium kernel. It supports both web pages and desktop applications. The back-end services are built using Node.js, and the database uses the relational database MySQL. The niche particle swarm algorithm is written in C++ and called through the Child_process module of Node.js.
[0139] The front-end of the embodiment of this application uses Vue 3 and Electron. Vue 3 provides an efficient responsive system and Composition API to improve performance and maintainability. Electron combines Chromium and Node.js to support cross-platform desktop application development and achieve seamless integration between the web and desktop. The back-end uses Node.js, leveraging its high concurrency processing capabilities to build API services and improve system performance and scalability. MySQL is used for data storage to process test cases and results, ensuring data integrity and query efficiency. Redis is used as a cache to optimize real-time data access and improve system response speed.
[0140] The main business process design of the automated testing platform is as follows:
[0141] 1) The user (test staff) enters the basic information of the test case in the test case template, including coverage strength, number of parameters, coverage location, etc.
[0142] 2) The user starts the test case generation function through the operation interface in the test case template;
[0143] 3) The operation interface transmits user instructions to the internal analysis and processing module;
[0144] 4) The system analyzes and processes the combination rule description of the module reading factors;
[0145] 5) After system analysis, the internal algorithm is called to generate combined test cases and display them;
[0146] 6) The test results are displayed in table format, supporting custom sorting;
[0147] 7) Users can view specific test data and obtain detailed analysis, including test time, specific algorithms, and function graphs between test count and coverage. The software system flow of this automated testing platform is as follows: Figure 4 As shown: Start the operation; select the function; if there is no data, add data for hyperparameter optimization, create a subprocess in the background to call the algorithm, obtain the test case, and obtain the result table; if there is data, choose to generate relevant parameters or generate a data table; enter the serial number according to the result table to obtain the result; test case modeling; test case mapping; obtain the test results.
[0148] The modular design of the automated testing platform's software services primarily includes user information, use case generation, statistical table generation, and data analysis modules. User Information: This module allows users to customize their basic information, including profile pictures, nicknames, gender, and region. Changes to profile pictures and nicknames automatically change. Use Case Generation: This module supports parameter management and test result visualization. Users can add, modify, and delete parameters, generate test cases, and display them in the order they were entered. The action column includes "Modify" and "Delete" buttons, allowing for automatic sorting after parameter adjustments or data deletions. This simplifies operational processes and database management, improving the flexibility and maintainability of test case generation. Statistics Generation: This module displays selected rows of data, supports sorting by specific columns, and provides Excel export functionality. Users can filter data by sequence number, and after sorting, click Export. The system automatically saves the data in Excel format, improving data management and sharing efficiency. Data Analysis: This module provides detailed analysis of selected test cases, including the number of generated cases, execution time, number of test combinations, algorithms used, and a graph showing the relationship between coverage and the number of generated cases. This provides testers with intuitive performance evaluation and data visualization support.
[0149] In a fourth aspect, an embodiment of the present application further provides an electronic device that can integrate the test case combination generating device provided in an embodiment of the present application. Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 5 The electronic device includes: an input device 43, an output device 44, a memory 42, and one or more processors 41; the memory 42 is used to store one or more programs; when the one or more programs are executed by the one or more processors 41, the one or more processors 41 implement the test case combination generation method provided in the above embodiment. The input device 43, the output device 44, the memory 42, and the processor 41 can be connected by a bus or other means. Figure 5 The bus connection is taken as an example.
[0150] The processor 41 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 42, that is, implements the above-mentioned test case combination generation method.
[0151] The electronic device provided above can be used to execute the test case combination generation method provided in the above embodiment, and has corresponding functions and beneficial effects.
[0152] In the fifth aspect, an embodiment of the present application also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the test case combination generation method as described above, and can achieve the same beneficial effects.
[0153] Of course, the storage medium containing computer-executable instructions provided in an embodiment of the present application, whose computer-executable instructions are not limited to the test case combination generation method described above, can also execute related operations in the test case combination generation method provided in any embodiment of the present application.
[0154] The computer program or instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program or instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired or wireless method. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; an optical medium, such as a digital video disk; or a semiconductor medium, such as a solid-state drive. The computer-readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.
[0155] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0156] In addition, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0157] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0158] The foregoing is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included within the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined or explained in subsequent figures.
[0159] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
Claims
1. A test case combination generation method, characterized in that: Applied to automated test platforms, including: Initialize particles and set the structure between particles to a ring topology; each particle represents a test case; Based on the set similarity measurement rules, the similarity between particles is measured and the fitness of particles is dynamically adjusted; Iterate the fitness according to the set update rules; When the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered, the iteration stops and the results are output; the output results include the global optimal solution or the approximate global optimal solution, and the output results are used as newly generated test cases.
2. The test case combination generation method according to claim 1, characterized in that: The dynamic adjustment of the fitness of the particles includes: The fitness of a particle is weightedly modified based on its minimum distance from other particles in the population and its coverage radius; When the minimum distance of a particle is large and the coverage radius is small, the fitness of the particle is improved; When the minimum distance is small or the coverage radius is large, the fitness of the particle is reduced.
3. The test case combination generation method according to claim 1, characterized in that: The initialization particles include: Initialize the position and velocity of the particles; each particle represents a test case, and the position of each particle corresponds to a parameter value combination of a test case; Initialize the historical optimal solution of each particle as the initial position of the particle, and initialize the best solution of all particles as the global optimal solution; Sort all particles by fitness and select the current best individual as the first leader particle; With the leader particle as the center, several particles are selected within a preset radius based on cosine distance to form a small habitat together with the leader particle; Remove all particles in the niche from the main population; Repeat the operation to continue selecting new leader particles from the remaining particles and dividing the niche until all particles are allocated; The particle with the best fitness in each niche is set as the corresponding local optimal solution.
4. The test case combination generation method according to claim 1, characterized in that: The similarity between particles is measured based on the set similarity measurement rules, including: The distance is used to measure the difference between any two test cases in the coverage array. The larger the minimum distance, the more obvious the difference between the test cases. The minimum distance is calculated as follows: Where C is a coverage array containing a set of test cases; x and y are any two test cases in the coverage array; ||xy|| represents the distance metric between the two; The coverage radius is used to measure the coverage capability of the covering array in the entire test space. The larger the coverage radius, the more test cases the covering array can cover. The calculation formula for coverage radius is as follows: Where g is an ideal point in the test space; x is any test case in the coverage array.
5. The test case combination generation method according to claim 1, characterized in that: The dynamic adjustment of the fitness of the particles includes: Adjust the fitness of particle calculations based on minimum distance and coverage radius: Score(C)=Coverage(C)+α·d(C)-β·ρ(C); Among them, Coverage(C) is the original fitness, d(C) is the minimum distance, ρ(C) is the coverage radius; α and β are set constants.
6. The test case combination generation method according to claim 1, characterized in that: The iterating of the fitness according to the set updating rule includes: If the current fitness of the particle is better than the fitness of its historical optimal solution, the historical optimal solution is updated to the current position of the particle; Calculate the fitness of each particle in each niche and compare it with the local optimal solution in the current niche; if the calculated fitness of the particle in the niche is better than the local optimal solution in the current niche, update the local optimal solution in the current niche to the position of the particle in the calculated niche; If the current fitness of the particle is better than the fitness of its global optimal solution, the global optimal solution is updated to the current position of the particle; Update the particle's velocity: V i (t+1)=ωV i (t)+c1γ1(pBest i (t)-X i (t))+c2γ2(Swarms localbest -X i (t)); Update the particle's position: X i (t+1)=X i (t)+V i (t+1); Among them, X i (t) is the position vector, X i (t) = [x i1 (t),x i2 (t),…,x id (t)]; Among them, V i (t) is the velocity vector, V i (t)=[v i1 (t),v i2 (t),…,v id (t)]; Among them, X i (t) and V i (t) represent the position and velocity of the particle at time t, X i (t+1) and V i (t+1) are the updated position and velocity respectively; ω is the inertia weight factor; c1 and c2 are acceleration factors greater than zero; y1,y2∈[0,1,0]; When updating the particle's position, a bounds check is performed to ensure that the particle's position is within the domain.
7. A test case combination generating device, characterized in that: Integrated into the automated testing platform, including: The particle initialization module is used to initialize particles and set the structure between particles to a ring topology; each particle represents a test case; The particle measurement module is used to measure the similarity between particles based on the set similarity measurement rules and dynamically adjust the fitness of particles; Iterative processing module, used to iterate the fitness according to the set update rules; The use case output module is used to stop the iteration and output the results when the maximum number of iterations is reached or all parameter interaction combinations to be covered are covered; the output results include the global optimal solution or the approximate global optimal solution, and the output results are used as the newly generated test cases.
8. A test case combination generation system, characterized in that: The test case combination generation system includes an automated testing platform, which includes: a test case combination generation module, a case operation module, a visualization module, and a test case combination generation device according to claim 7 connected to the test case combination generation module; The test case combination generation module is used for parameter input and algorithm selection; the case operation module is used for parameter modification and parameter deletion; and the visualization module is used for displaying test results and displaying chart analysis.
9. An electronic device, characterized in that: include: A processor, a memory, and a bus, wherein the processor is connected to the memory via the bus, and the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the method for generating a test case combination according to any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a server, implements the test case combination generating method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Combined test case generation method based on CS-SPSO algorithm
CN110334026A
Multi-modal feature selection method based on particle swarm algorithm
CN111723897A
Method for automatically generating data flow test case based on particle swarm optimization algorithm
CN113377646A
Test case sorting method and device, equipment and storage medium
CN115629987A
Industrial big data multi-modal feature selection method and device, equipment and medium
CN117093844A