CN115248781A - Combined test case generation method, device and equipment and readable storage medium - Google Patents

Combined test case generation method, device and equipment and readable storage medium Download PDF

Info

Publication number
CN115248781A
CN115248781A CN202211155924.XA CN202211155924A CN115248781A CN 115248781 A CN115248781 A CN 115248781A CN 202211155924 A CN202211155924 A CN 202211155924A CN 115248781 A CN115248781 A CN 115248781A
Authority
CN
China
Prior art keywords
sets
test cases
test case
combinations
test
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202211155924.XA
Other languages
Chinese (zh)
Other versions
CN115248781B (en
Inventor
谭丽红
潘娅
范勇
孙岩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Southwest University of Science and Technology
Original Assignee
Southwest University of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Southwest University of Science and Technology filed Critical Southwest University of Science and Technology
Priority to CN202211155924.XA priority Critical patent/CN115248781B/en
Publication of CN115248781A publication Critical patent/CN115248781A/en
Application granted granted Critical
Publication of CN115248781B publication Critical patent/CN115248781B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/004Artificial life, i.e. computing arrangements simulating life
    • G06N3/006Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]

Abstract

The application discloses a method, a device and equipment for generating a combined test case and a readable storage medium in the technical field of computers. According to the method, when the number of combinations in the deleted uncovered sets is determined to be not 0, the next iteration is not directly performed on the update sets, but when migration conditions are met, the update sets are copied to obtain two same update sets, after the two same update sets are subjected to individual random variation respectively, the two same update sets are used as initial sets respectively, and the step of traversing the initial sets is performed, so that the iterative updating step is started simultaneously based on the two same update sets, the effect of multi-set merging and calculation can be achieved, the global search range is enlarged, the probability of being trapped into local optimum can be reduced, the current result set can be rapidly and accurately output, the number of test cases in the finally output current result set is small, and the test overhead can be reduced. The combined test case generation device, the equipment and the readable storage medium provided by the application also have the technical effects.

Description

Combined test case generation method, device and equipment and readable storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a readable storage medium for generating a combined test case.
Background
At present, the method for generating the combined test case has a plurality of problems. For example: the particle swarm algorithm is easy to get early, a global optimal path is easy to miss, and the dependence of an algorithm result on parameter selection is large; the simulated annealing algorithm has a complex structure and relatively long optimization time.
Therefore, how to generate the combined test case quickly and accurately is a problem to be solved by those skilled in the art.
Disclosure of Invention
In view of the above, an object of the present application is to provide a method, an apparatus, a device and a readable storage medium for generating a combined test case, so as to generate the combined test case quickly and accurately. The specific scheme is as follows:
in a first aspect, the present application provides a method for generating a combined test case, including:
generating an initial set comprising N test cases;
traversing the initial set, combining values of K parameters to be tested of the currently traversed test case with two non-repeated combinations to obtain a plurality of combinations, deleting the combinations covered by the current result set from the plurality of combinations to obtain the combinations covered by the current test case, and determining the combinations covered by each test case;
selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of the two test cases in each pair of test cases to obtain a pair of filial generations corresponding to each pair of test cases;
randomly mutating each child, adding random mutation results to the initial set to expand the initial set, taking the first N test cases with the number of combinations in descending order in the expanded initial set to form an updated set, and adding the target test case with the maximum number of combinations in the updated set to the current result set;
deleting the combination corresponding to the target test case from the current uncovered set; if the number of the deleted non-covered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering a step of traversing the initial sets; and if the number of the combinations in the deleted uncovered set is 0, outputting the current result set.
Optionally, the selecting multiple pairs of test cases in the initial set based on the number of combinations covered by each test case includes:
calculating the probability of each test case being selected based on the combined number of each test case, and selecting X pairs of test cases based on the probability of each test case being selected; wherein, X = N × W, and W is a preset proportion.
Optionally, partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of offspring corresponding to each pair of test cases includes:
for each pair of test cases, the following steps are performed: respectively coding the values of K parameters to be tested of two test cases in any pair of test cases into arrays to obtain two arrays; exchanging partial parameter values in the two arrays to obtain two new arrays; and taking the two new arrays as a pair of descendants corresponding to the pair of test cases.
Optionally, exchanging the partial parameter values in the two arrays includes:
and randomly determining a switching position, and switching parameter values after the switching position in the two arrays.
Optionally, the randomly mutating each child and adding a random mutation result to the initial set to expand the initial set comprises:
for each child, the following steps are performed: randomly determining the variation probability of any filial generation, and if the variation probability is not greater than a variation threshold, randomly varying the filial generation; otherwise, the child is not altered.
Optionally, the randomly mutating the offspring comprises:
an array representing the child is determined, and the value of the parameter at any position in the array is changed.
Optionally, the method further comprises:
if the number of the combinations in the deleted uncovered sets is not 0, carrying out individual random variation on the updated sets when the migration conditions are not met, taking the updated sets after the individual random variation as the initial sets, and entering the step of traversing the initial sets.
In a second aspect, the present application provides a combined test case generating apparatus, including:
the generating module is used for generating an initial set comprising N test cases;
the traversal module is used for traversing the initial set, combining values of K parameters to be tested of the currently traversed test case with two values to obtain a plurality of combinations, deleting the combinations covered by the current result set from the plurality of combinations to obtain the combinations covered by the current test case, and determining the combinations covered by each test case;
the child generation module is used for selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of children corresponding to each pair of test cases;
the updating module is used for enabling each child to randomly mutate and adding random mutation results to the initial set so as to expand the initial set, taking the first N test cases with the number of combinations in descending order in the expanded initial set to form an updating set, and adding the target test case with the largest number of combinations in the updating set to the current result set;
the iteration module is used for deleting the combination corresponding to the target test case from the current uncovered set; if the number of the combinations in the deleted uncovered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering the step of traversing the initial sets;
and the output module is used for outputting the current result set if the number of the combinations in the deleted uncovered set is 0.
In a third aspect, the present application provides an electronic device, comprising:
a memory for storing a computer program;
and the processor is used for executing the computer program to realize the combined test case generation method disclosed by the foregoing.
In a fourth aspect, the present application provides a readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the combined test case generation method disclosed in the foregoing.
According to the scheme, the combined test case generation method comprises the following steps: generating an initial set comprising N test cases; traversing the initial set, combining values of K parameters to be tested of the currently traversed test case with two non-repeated combinations to obtain a plurality of combinations, deleting the combinations covered by the current result set from the plurality of combinations to obtain the combinations covered by the current test case, and determining the combinations covered by each test case; selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of filial generations corresponding to each pair of test cases; randomly mutating each child, adding random mutation results to the initial set to expand the initial set, taking the first N test cases with the number of combinations in descending order in the expanded initial set to form an updated set, and adding the target test case with the maximum number of combinations in the updated set to the current result set; deleting the combination corresponding to the target test case from the current uncovered set; if the number of the combinations in the deleted uncovered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering the step of traversing the initial sets; and if the number of the combinations in the deleted uncovered set is 0, outputting the current result set.
It can be seen that, when it is determined that the number of combinations in the deleted uncovered sets is not 0, the next iteration is not directly performed on the update sets, but when migration conditions are met, the update sets are copied to obtain two identical update sets, after the two identical update sets are subjected to individual random variation respectively, the two identical update sets are used as initial sets respectively, and the step of traversing the initial sets is performed.
Accordingly, the combined test case generation device, the combined test case generation equipment and the readable storage medium have the technical effects.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flow chart of a method for generating a combined test case disclosed in the present application;
FIG. 2 is a schematic view of a crossover operation disclosed herein;
FIG. 3 is a schematic diagram of a variant operation disclosed herein;
FIG. 4 is a flowchart of a method for generating a combined test case in combination with a genetic algorithm according to the present disclosure;
FIG. 5 is a schematic diagram of a combined test case generation apparatus disclosed in the present application;
fig. 6 is a schematic diagram of an electronic device disclosed in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
At present, the method for generating the combined test case has a plurality of problems. For example: the particle swarm algorithm is easy to get early, a global optimal path is easy to miss, and the dependence of an algorithm result on parameter selection is large; the simulated annealing algorithm has a complex structure and relatively long optimization time. Therefore, the combined test case generation scheme is provided, the global search range can be enlarged, the probability of trapping in local optimum is reduced, and therefore the combined test case is generated quickly and accurately.
Referring to fig. 1, an embodiment of the present application discloses a method for generating a combined test case, including:
s101, generating an initial set comprising N test cases.
In this embodiment, each test case in the initial set is represented by an array, and each value in the array is: and taking values of K parameters to be tested by the current test case. And each test case in the initial set carries out value test on the K parameters of p1, p2, pk. Specifically, if the test case R is to test the case where K parameters p1, p2,. And pk are all equal to 0, then the array R of the test case R = {00.. 0} includes K0 in total.
S102, traversing the initial set, combining values of K parameters to be tested of the currently traversed test cases repeatedly to obtain a plurality of combinations, deleting the combinations covered by the current result set from the plurality of combinations to obtain the combinations covered by the current test cases, and determining the combinations covered by each test case.
The values of K parameters to be tested of the currently traversed test case are combined repeatedly, and each obtained combination comprises two parameter values. It should be noted that the combination covered by the current result set can be tested by using the test case in the current result set, and thus the combination does not need to be tested repeatedly by using the currently traversed test case, and the combination covered by the current result set is deleted from the currently obtained combination.
Of course, since the number of test cases in the initial set is limited, the total covered combinations of N test cases in the initial set are also limited, and therefore, an uncovered set may be set to include the uncovered combinations of N test cases in the initial set. At the beginning of the process of this embodiment, the uncovered set includes pairwise combinations of all values of the K parameters, and the values are not limited to the values to be tested for the N test cases in the initial set.
S103, selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of filial generations corresponding to each pair of test cases.
In a specific embodiment, selecting pairs of test cases in an initial set based on the number of combinations covered by each test case includes: and calculating the selection probability of each test case based on the combined number of each test case, selecting X pairs of test cases based on the selection probability of each test case, and selecting the test cases based on the mode, wherein the test cases with more combinations are easier to select. The selected test cases are the basis for generating the combined test cases, so the combined test cases can be generated by the test cases with more combinations, and the combined test cases can cover more combinations, thereby improving the test performance of the combined test cases. Wherein, X = N × W, and W is a preset proportion. The preset proportion W is used for limiting the number of the selected test cases.
In this embodiment, each time a pair of test cases is selected in the initial set according to the probability that each test case is selected, a pair is still selected in the initial set according to the probability that each test case is selected next time, and this is repeated until X pairs are selected.
In a specific embodiment, partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of offspring corresponding to each pair of test cases, includes: for each pair of test cases, the following steps are performed: respectively coding the values of K parameters to be tested of two test cases in any pair of test cases into arrays to obtain two arrays; exchanging partial parameter values in the two arrays to obtain two new arrays; and taking the two new arrays as a pair of descendants corresponding to the pair of test cases. Exchanging partial parameter values in the two arrays comprises the following steps: and randomly determining the exchange position, and exchanging the parameter values after the exchange position in the two arrays.
As described above, each test case is represented by an array, and the values in the array are: if the values of the K parameters to be tested by the current test case are obtained, the values of the K parameters to be tested by the two test cases in each pair of test cases are partially exchanged, namely: swapping the partial parameter values in the two arrays representing the two test cases, it is necessary to determine which parameter values to swap. For this purpose, the switching positions in the arrays can be determined randomly and the parameter values in both arrays after the switching positions can then be switched. Referring to fig. 2, fig. 2 schematically shows: an array a = {01112001021} indicating test case a, an array B = {12111222100} indicating test case B, and a total of 11 parameter values in the arrays a, B indicate K =11. Assuming that the randomly determined swap position is bit 5, "001021" after bit 5 in array A is swapped with "222100" after bit 5 in array B, so that two new arrays A1= {01112222100} and B1= {12111001021} are available based on arrays A, B. Naturally, a pair of descendants corresponding to the test cases A and B is obtained: a1= {01112222100} and B1= {12111001021}.
The exchange position is used for determining which parameter values in the array need to be exchanged, so that the exchange position randomly takes a value in an interval [1, K-1], and K is the number of the parameters.
And S104, randomly mutating each child, adding a random mutation result to the initial set to expand the initial set, taking the first N test cases with the number of the combination in descending order in the expanded initial set to form an updated set, and adding the target test case with the largest combination number in the updated set to the current result set.
In one embodiment, randomly mutating each child and adding the random mutation results to the initial set to expand the initial set, comprises: for each child, the following steps are performed: randomly determining the variation probability of any filial generation, and if the variation probability is not greater than a variation threshold, randomly varying the filial generation; otherwise, the child is not altered. Wherein randomly mutating the offspring comprises: an array representing the child is determined, and the parameter value at any position in the array is changed. Wherein, the change of the parameter value needs to be determined in the value range of the corresponding parameter.
In this embodiment, the variation of any one child may be: any parameter value in the array representing the child has changed; the parameter value that changes may be one or more. When the parameter value that changes is one, the parameter value at any position in the array representing any child may be changed. In order to determine the variation position of the filial generation, random values can be taken in the interval [1, K ], K is the number of parameters, and the value is several, so that the number of the filial generation is varied.
Referring to fig. 3, for the child A1= {01112222100}, change the "2" of the 7 th bit to "4", where "4" is another value of the 7 th bit parameter, and the resulting a11= {01112242100}, which is a variant of the child A1. "1, 2,3, 4" shown in fig. 3 are 4 values of the 7 th bit parameter. Variants a11 of progeny A1 are subsequently filled into the initial set. If the mutation probability of the child B1 is not larger than the mutation threshold, the child B1 does not mutate, and then the child B1 is directly filled into the initial set. Therefore, the number of the test cases in the expanded initial set is more than N, in order to keep the number of the test cases at N, the first N test cases with a plurality of combinations in the expanded initial set are taken to form an update set, and then one or more target test cases with the largest number of combinations in the update set are added to the current result set, wherein the target test cases are the combined test cases selected in the round. When the process of this embodiment starts, the current result set is empty, and every time a round passes, a target test case is added to the current result set, until the number of combinations in the deleted uncovered set is 0, all target test cases included in the current result set are the combined test cases generated in this embodiment.
It should be noted that the parameter values in the present embodiment are all encoded values of actual parameter values. Assuming that a parameter needs to be tested by taking values in "-0.1, 0,0.1,0.39,0.4,0.41,0.79,0.8,0.81,1.19,1.2,1.21,4.99,5, 5.1", the parameter values can be encoded individually as: 0.1, 2,3,4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 to facilitate subsequent processing.
It should be noted that the test values of the parameters may be determined according to the following process. Assume that one of the parameters tested is weight (M) and there are 5 value divisions for weight as follows: when M is more than or equal to 0 and less than 0.4g, the material is an ultra-light object; when M is more than or equal to 0.4g and less than 0.8g, the material is a lighter object; when M is more than or equal to 0.8g and less than 1.2g, the weight is a standard weight object; when M is more than or equal to 1.2g and less than 5g, the object is a heavy object; when M is more than or equal to 5g, the object is overweight. If M is less than or equal to 0, the weight value is invalid. Therefore, for the weight parameter, 5 effective values can be used as effective equivalence classes, M is less than or equal to 0 and is used as an ineffective equivalence class, then, one value is selected from 6 equivalence classes respectively, a parameter value set Vi = { -0.1,0.2,0.5,1,3,8} is formed, and the set Vi comprises 6 parameters.
And next, taking the range boundary of the parameter and the near value around the range boundary as test values according to the parameter value range specified by the boundary value analysis method. Such as: and for M which is more than or equal to 0.4 and less than 0.8, taking boundary values of 0.4 and 0.8, and taking approximate values of 0.4 and 0.8: 0.39,0.41,0.79 and 0.81, so when the boundary value analysis method is used for ultra-light objects, the parameter values are {0.39,0.4,0.41,0.79,0.8 and 0.81}. And obtaining a value set Vj = { -0.1,0,0.1,0.39,0.4,0.41,0.79,0.8,0.81,1.19,1.2,1.21,4.99,5,5.1} of the weight after the values of the 6 equivalence classes are obtained by using a boundary value analysis method and removing repeated values. Thus, the range of values of the weight to be tested is determined. The value to be measured can be determined for each parameter according to the above process. And S105, deleting the combination corresponding to the target test case from the current uncovered set.
S106, judging whether the number of the deleted uncovered sets is 0; if yes, entering S107; otherwise, the process proceeds to S108.
And S107, outputting the current result set, and ending the process.
S108, judging whether the migration condition is met; if yes, entering S109; otherwise, the process proceeds to S110.
And S109, copying the update sets to obtain two same update sets, respectively carrying out individual random variation on the two same update sets, and respectively taking the two sets subjected to the individual random variation as initial sets to enter S102.
S110, carrying out individual random variation on the current update set, taking the set subjected to the individual random variation as an initial set, and entering S102.
Wherein, carrying out individual random variation on one set: some test cases are randomly selected from the set, and then parameter values at any position in the array of the selected test cases are changed. Specifically, a mutation probability may be randomly generated for each test case in one set, and if the mutation probability is less than or equal to a mutation probability threshold, a parameter value at any position in an array representing the test case is changed; otherwise, the array representing the test case is not changed.
In this embodiment, whether or not the migration condition is determined by a random function, for example: randomly outputting a numerical value by using a random function, and if the numerical value is smaller than the preset migration probability, considering that the numerical value meets the migration condition; otherwise, the migration condition is considered not to be met. When the migration condition is met, two identical update sets can be obtained, the two identical update sets are subjected to individual random variation respectively, the next round of processing is performed on the two sets subjected to random variation respectively in S102-S110, and if the next round of processing on the two sets subjected to random variation also meets the migration condition, the next round of processing is performed on the 4 sets respectively in S102-S110. And when the migration condition is not met, executing S102-S110 only for one set after random mutation in the next round.
It can be seen that, in this embodiment, when it is determined that the number of combinations in the deleted uncovered set is not 0, the next iteration is not directly performed on the update set, but when the migration condition is met, the update set is copied to obtain two identical update sets, after the two identical update sets are respectively subjected to individual random variation, the two identical update sets are respectively used as initial sets, and the step of traversing the initial sets is performed, so that the iterative update step is simultaneously started based on the two identical update sets, the effect of multi-set merging calculation can be achieved, the global search range is enlarged, the probability of being trapped in local optimum can be reduced, the current result set can be quickly and accurately output, the number of test cases in the finally output current result set is small, and the test overhead can be reduced.
The following examples are presented as a scheme incorporating a genetic algorithm, with particular reference to FIG. 4. Fig. 4 starts with step 3.
Step 1: and extracting test parameters from the test requirements, and determining parameter values by using a boundary value analysis method and an equivalence class division method of the black box test.
Step 1.1: determining a software module to be tested and parameters to be tested according to the test requirements of the software system to be tested, and forming a parameter set P = { P1, P2.
Step 1.2: carrying out equivalence class division on the value of each measured parameter, and then respectively selecting a value from each equivalence class aiming at the equivalence class corresponding to any parameter to form a parameter value set Vi; and then, determining a value set Vj of the current parameter by using a boundary value analysis method on the basis of Vi.
And 2, step: and coding each parameter value in the value set Vj of each parameter so as to facilitate subsequent processing. For example: the specific parameter values are replaced by numbers such as 0,1,2,3,4, and the like.
And step 3: initializing population and genetic algorithm parameters: generating an empty cluster QS, setting the upper limit of iteration steps of the algorithm, setting the number N of individuals in a single cluster to be 60, setting the proportion nPop of cross generation filial generations to be 1, setting the variation probability nMu of the filial generations to be 0.1, adopting single-point variation in the variation method, and setting the migration probability nNi of the clusters to be 0.1.
And 4, step 4: randomly generating a population, wherein the population comprises 60 randomly generated test case individuals, calculating the pairwise combination covered by each test case individual, taking the number of the combinations as the fitness of the individual, wherein a result set TS = { t1, t2.. Tn } corresponding to the population is empty initially, and two corresponding combinations CS which are not covered comprise pairwise combinations of all parameter values. The population is added to the population and the population is selected for the following steps.
And 5: individuals in the population undergo cross variation and progeny is generated.
Step 5.1: the individual cross operation adopts a single-point cross mode.
Step 5.1.1: roulette is used to identify individuals who need to cross. Assuming an individualx i Is expressed asf(x i ) The probability of the individual being selected isp(x i ) The corresponding calculation formula is:
Figure 57446DEST_PATH_IMAGE001
wherein, in the step (A),f(x i ) Is equal to individualx i When the degree of adaptability of the device is high,
Figure 443428DEST_PATH_IMAGE002
the fitness of all individuals in the population is equal to the sum of the fitness of all individuals in the population; the sum of the fitness of all individuals in the population is: the number of combinations in CS in the initial state. By using the method to select one pair of individuals at a time and limiting the number of the selected individuals based on the proportion of filial generation, the individuals with larger combination number can be selected more easily.
Step 5.1.2: and determining individual crossing positions for each pair of individuals and performing crossing operation.
As shown in fig. 2, the individuals are represented by an array including 11 numbers, an integer is randomly selected in the interval [1,10], and assuming that the selected integer is 5, the operation is interleaved from the value after the 5 th bit, so that the descendants {01112222100} and B1= {12111001021} are interleaved for {01112001021} and {12111222100 }.
Step 5.2: to increase the global search power of the algorithm, the offspring mutation probability is set to 0.1, and random occurs at random positions on each offspring. For each filial generation, if the mutation probability generated randomly for the filial generation is less than or equal to 0.1, carrying out mutation operation on the filial generation according to the graph 3; otherwise, the progeny is not mutated. As shown in FIG. 3, an integer 7 is randomly selected from the interval [1,11], and then a mutation is made at position 7 to obtain a progeny variant.
Step 6: adding the variant into the population aiming at the variant offspring; adding the offspring which is not mutated into the population, and calculating the fitness of each newly added individual; and (3) arranging all individuals in the population in a descending order according to fitness, only taking the first 60 individuals, reserving the individuals into the next generation, and completely eliminating the rest individuals.
And 7: and selecting the individuals with the highest fitness from the reserved individuals, adding the individuals to a result set TS corresponding to the population, and simultaneously removing pairwise combinations covered by the individuals from the uncovered two-group combination sets CS. Assuming that the fitness of the current individual {1,2,1, 0,1,0,2,1} is highest, it is added to the TS while the 55 pairwise combinations covered by that individual are removed from the CS.
And 8: generating a random number from 0 to 1, and if the generated random number is less than a preset migration probability of 0.1, migrating the population, namely: the currently reserved population of all individuals is replicated so that there are 2 identical populations in the species cluster QS.
And step 9: if an unexplained population is present in the species cluster QS, the population is selected for step 5-8. If all populations have evolved, go to step 10.
Step 10: after all the populations needing to be evolved in the current generation are evolved, all the populations are subjected to individual random variation, and fitness is calculated. The change of the CS is like the environmental mutation, so that the fitness of part of individuals is reduced, and in order to avoid losing the optimal solution, a step of random variation of the individuals is added to improve the algorithm optimizing path.
Step 11: and (5) repeating the steps (5-10) until the uncovered two sets of aggregation CS corresponding to a certain population is empty or reaches the iteration upper limit, and stopping the algorithm.
And the result set TS corresponding to the population with the CS being empty is the output result of the algorithm.
If the CS of none of the clusters is empty when the iteration upper limit is reached, selecting the cluster with the minimum CS from the cluster QS, and taking the TS corresponding to the cluster with the minimum CS as the output of the algorithm. And if the CS is minimum, selecting the population with the minimum number of individuals from the population with the minimum CS, and taking the TS corresponding to the population with the minimum number of individuals as the output of the algorithm.
Therefore, the population migration step is added to the traditional genetic algorithm, parallel independent calculation of a plurality of populations can be realized, and the optimal population is selected as the algorithm result. In the method, each population is divided into two populations according to a certain probability, each population has an independent test case set and two uncovered sets, when the number of uncovered sets of a certain population is 0, the algorithm is ended, and the test case set corresponding to the population is used as an algorithm return value. According to the invention, the parameter extraction is carried out on the parameter input domain by the black box test method, so that test cases required to be generated are reduced; the problem of test case generation is abstracted to be a biological genetic problem, meanwhile, the individual richness of the population is increased through population migration operation, the number of the generated test cases and the test case generation time can be greatly reduced, and the test overhead is reduced.
In the following, a combined test case generating apparatus provided in an embodiment of the present application is introduced, and a combined test case generating apparatus described below and a combined test case generating method described above may refer to each other.
Referring to fig. 5, an embodiment of the present application discloses a combined test case generation apparatus, including:
a generating module 501, configured to generate an initial set including N test cases;
a traversal module 502, configured to traverse the initial set, combine values of K parameters to be tested of the currently traversed test case with two or more values to obtain multiple combinations, delete a combination covered by the current result set from the multiple combinations, obtain a combination covered by the current test case, and determine a combination covered by each test case;
a child generation module 503, configured to select multiple pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchange values of K parameters to be tested by two test cases in each pair of test cases to obtain a pair of children corresponding to each pair of test cases;
an updating module 504, configured to randomly mutate each child, add a random mutation result to the initial set to expand the initial set, form an updated set by taking the first N test cases with the descending combination number in the expanded initial set, and add the target test case with the largest combination number in the updated set to the current result set;
an iteration module 505, configured to delete a combination corresponding to the target test case from the current uncovered set; if the number of the deleted non-covered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering a step of traversing the initial sets;
an output module 506, configured to output the current result set if the number of combinations in the deleted uncovered set is 0.
In a specific embodiment, the child generation module is specifically configured to:
calculating the probability of each test case being selected based on the combined number of each test case, and selecting X pairs of test cases based on the probability of each test case being selected; wherein, X = N × W, and W is a preset proportion.
In one embodiment, the child generation module is specifically configured to:
for each pair of test cases, the following steps are performed: respectively coding the values of K parameters to be tested of two test cases in any pair of test cases into arrays to obtain two arrays; exchanging partial parameter values in the two arrays to obtain two new arrays; and taking the two new arrays as a pair of descendants corresponding to the pair of test cases.
In a specific embodiment, the child generation module is specifically configured to:
and randomly determining the exchange position, and exchanging the parameter values after the exchange position in the two arrays.
In a specific embodiment, the update module is specifically configured to:
for each child, the following steps are performed: randomly determining the variation probability of any filial generation, and if the variation probability is not greater than a variation threshold, randomly varying the filial generation; otherwise, the child is not altered.
In a specific embodiment, the update module is specifically configured to:
an array representing the child is determined, and the value of the parameter at any position in the array is changed.
In a specific embodiment, the method further comprises the following steps:
and the other iteration module is used for carrying out individual random variation on the updated set if the number of the combinations in the deleted uncovered set is not 0 and the migration condition is not met, taking the updated set subjected to the individual random variation as an initial set, and entering the step of traversing the initial set.
For more specific working processes of each module and unit in this embodiment, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not described here again.
Therefore, the embodiment provides a combined test case generation device, which can increase the global search range and reduce the probability of trapping into local optimum, thereby generating the combined test case quickly and accurately.
In the following, an electronic device provided by an embodiment of the present application is introduced, and the electronic device described below and the method and the apparatus for generating a combined test case described above may refer to each other.
Referring to fig. 6, an embodiment of the present application discloses an electronic device, including:
a memory 601 for storing a computer program;
a processor 602 configured to execute the computer program to implement the method disclosed in any of the embodiments.
In the following, a readable storage medium provided by an embodiment of the present application is introduced, and a readable storage medium described below and a combined test case generation method, an apparatus, and a device described above may be referred to each other.
A readable storage medium is used for storing a computer program, wherein the computer program realizes the combined test case generation method disclosed in the foregoing embodiment when executed by a processor. For the specific steps of the method, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
References in this application to "first," "second," "third," "fourth," etc., if any, are intended to distinguish between similar elements and not necessarily to describe a particular order or sequence. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be implemented in other sequences than those illustrated or described herein. Moreover, the terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, or apparatus.
It should be noted that the descriptions in this application referring to "first", "second", etc. are for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present application.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of readable storage medium known in the art.
The principle and the implementation of the present application are explained herein by applying specific examples, and the above description of the embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method for generating a combined test case is characterized by comprising the following steps:
generating an initial set comprising N test cases;
traversing the initial set, combining values of K parameters to be tested of the currently traversed test cases repeatedly to obtain a plurality of combinations, deleting the combinations covered by the current result set from the combinations to obtain the combinations covered by the current test cases, and determining the combination covered by each test case;
selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of filial generations corresponding to each pair of test cases;
randomly mutating each child, adding random mutation results to the initial set to expand the initial set, taking the first N test cases with the number of combinations in descending order in the expanded initial set to form an updated set, and adding the target test case with the maximum number of combinations in the updated set to the current result set;
deleting the combination corresponding to the target test case from the current uncovered set; if the number of the deleted non-covered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering a step of traversing the initial sets; and if the number of the combinations in the deleted uncovered sets is 0, outputting the current result set.
2. The method of claim 1, wherein selecting pairs of test cases in the initial set based on a combined number covered by each test case comprises:
calculating the probability of each test case being selected based on the combined number of each test case, and selecting X pairs of test cases based on the probability of each test case being selected; wherein, X = N × W, and W is a preset proportion.
3. The method according to claim 1, wherein partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of descendants corresponding to each pair of test cases comprises:
for each pair of test cases, the following steps are performed: respectively coding the values of K parameters to be tested of two test cases in any pair of test cases into arrays to obtain two arrays; exchanging partial parameter values in the two arrays to obtain two new arrays; and taking the two new arrays as a pair of filial generations corresponding to the pair of test cases.
4. The method of claim 3, wherein the swapping the partial parameter values in the two arrays comprises:
and randomly determining a switching position, and switching parameter values after the switching position in the two arrays.
5. The method of claim 1, wherein randomly mutating each child and adding a random mutation result to the initial set to expand the initial set comprises:
for each child, the following steps are performed: randomly determining the variation probability of any filial generation, and if the variation probability is not greater than a variation threshold, randomly varying the filial generation; otherwise, the child is not altered.
6. The method of claim 5, wherein said randomly mutating the offspring comprises:
an array representing the child is determined, and the parameter value at any position in the array is changed.
7. The method of any of claims 1 to 6, further comprising:
if the number of the deleted non-covered sets is not 0, if the migration condition is not met, performing individual random variation on the updated set, taking the updated set subjected to the individual random variation as the initial set, and performing the step of traversing the initial set.
8. A combination test case generation apparatus, comprising:
the generating module is used for generating an initial set comprising N test cases;
the traversal module is used for traversing the initial set, combining values of K parameters to be tested of the currently traversed test case with two values to obtain a plurality of combinations, deleting the combinations covered by the current result set from the plurality of combinations to obtain the combinations covered by the current test case, and determining the combinations covered by each test case;
the child generation module is used for selecting a plurality of pairs of test cases in the initial set based on the number of combinations covered by each test case, and partially exchanging values of K parameters to be tested of two test cases in each pair of test cases to obtain a pair of children corresponding to each pair of test cases;
the updating module is used for enabling each filial generation to be subjected to random variation, adding a random variation result to the initial set so as to expand the initial set, taking the first N test cases with the combined number in descending order in the expanded initial set to form an updating set, and adding the target test case with the largest combined number in the updating set to the current result set;
the iteration module is used for deleting the combination corresponding to the target test case from the current uncovered set; if the number of the combinations in the deleted uncovered sets is not 0, copying the update sets to obtain two same update sets when the migration condition is met, respectively carrying out individual random variation on the two same update sets, respectively taking the two sets subjected to the individual random variation as the initial sets, and entering the step of traversing the initial sets;
and the output module is used for outputting the current result set if the number of the combinations in the deleted uncovered set is 0.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the method of any one of claims 1 to 7.
10. A readable storage medium for storing a computer program, wherein the computer program when executed by a processor implements the method of any one of claims 1 to 7.
CN202211155924.XA 2022-09-22 2022-09-22 Combined test case generation method, device, equipment and readable storage medium Active CN115248781B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211155924.XA CN115248781B (en) 2022-09-22 2022-09-22 Combined test case generation method, device, equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211155924.XA CN115248781B (en) 2022-09-22 2022-09-22 Combined test case generation method, device, equipment and readable storage medium

Publications (2)

Publication Number Publication Date
CN115248781A true CN115248781A (en) 2022-10-28
CN115248781B CN115248781B (en) 2022-12-27

Family

ID=83699697

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211155924.XA Active CN115248781B (en) 2022-09-22 2022-09-22 Combined test case generation method, device, equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN115248781B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115617700A (en) * 2022-12-19 2023-01-17 华东交通大学 Test case design and generation method and system based on relational analysis
CN116089317A (en) * 2023-04-10 2023-05-09 江西财经大学 Multipath testing method and system based on path similarity table and individual migration

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102855185A (en) * 2012-07-24 2013-01-02 河海大学 Pair-wise test method based on priority
CN105117326A (en) * 2015-07-01 2015-12-02 湖州师范学院 Test case set generation method based on combination chaotic sequence
CN109344057A (en) * 2018-09-18 2019-02-15 北京航空航天大学 Combination accelerated test case generation method based on genetic method and semiology analysis
CN110515845A (en) * 2019-08-20 2019-11-29 义乌工商职业技术学院 Optimize generation method based on the combined test use-case for improving IPO strategy
CN112699045A (en) * 2020-08-03 2021-04-23 徐州工程学院 Software test case generation method based on multi-population genetic algorithm
CN113051148A (en) * 2019-12-26 2021-06-29 南京邮电大学 Combined test case generation method based on double-gene-chain genetic algorithm
CN113900942A (en) * 2021-10-09 2022-01-07 电子科技大学 Method for generating simplified test case set of flight control machine-mounted model
CN114064453A (en) * 2021-10-12 2022-02-18 华南理工大学 Software test case automatic generation method based on clustering and evolutionary algorithm
CN114185800A (en) * 2021-12-16 2022-03-15 中国电信股份有限公司 Test case generation method, system, equipment and medium based on genetic algorithm
CN114490316A (en) * 2021-12-16 2022-05-13 四川大学 Loss function-based automatic generation method for unit test case

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102855185A (en) * 2012-07-24 2013-01-02 河海大学 Pair-wise test method based on priority
CN105117326A (en) * 2015-07-01 2015-12-02 湖州师范学院 Test case set generation method based on combination chaotic sequence
CN109344057A (en) * 2018-09-18 2019-02-15 北京航空航天大学 Combination accelerated test case generation method based on genetic method and semiology analysis
CN110515845A (en) * 2019-08-20 2019-11-29 义乌工商职业技术学院 Optimize generation method based on the combined test use-case for improving IPO strategy
CN113051148A (en) * 2019-12-26 2021-06-29 南京邮电大学 Combined test case generation method based on double-gene-chain genetic algorithm
CN112699045A (en) * 2020-08-03 2021-04-23 徐州工程学院 Software test case generation method based on multi-population genetic algorithm
CN113900942A (en) * 2021-10-09 2022-01-07 电子科技大学 Method for generating simplified test case set of flight control machine-mounted model
CN114064453A (en) * 2021-10-12 2022-02-18 华南理工大学 Software test case automatic generation method based on clustering and evolutionary algorithm
CN114185800A (en) * 2021-12-16 2022-03-15 中国电信股份有限公司 Test case generation method, system, equipment and medium based on genetic algorithm
CN114490316A (en) * 2021-12-16 2022-05-13 四川大学 Loss function-based automatic generation method for unit test case

Non-Patent Citations (9)

* Cited by examiner, † Cited by third party
Title
TOSHIAKI SHIBA等: "Using Artificial Life Techniques to Generate Test Cases for Combinatorial Testing", 《PROCEEDINGS OF THE 28TH ANNUAL INTERNATIONAL COMPUTER SOFTWARE AND APPLICATIONS CONFERENCE, 2004. COMPSAC 2004.》 *
YA PAN等: "Automatic Test Case Generation and Optimization Based on Mutation Testing", 《2019 IEEE 19TH INTERNATIONAL CONFERENCE ON SOFTWARE QUALITY, RELIABILITY AND SECURITY COMPANION (QRS-C)》 *
惠战伟等: "成对覆盖组合测试用例生成方法研究", 《PROCEEDINGS OF 2010 ASIA-PACIFIC CONFERENCE ON INFORMATION THEORY (APCIT 2010)》 *
李晨晨等: "基于IRAPSO的组合测试用例生成方法", 《浙江理工大学学报(自然科学版)》 *
李玉: "组合测试用例生成方法的研究与应用", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *
杜畇岐: "基于变异技术的测试用例自动生成及优化", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *
王曙燕等: "基于并行化粒子群算法的组合测试用例生成", 《西安邮电大学学报》 *
钱雪忠等: "求解组合测试用例集的差分进化蚁群算法", 《计算机工程与应用》 *
陈清媛等: "基于多核并行遗传算法并行生成测试用例", 《微电子学与计算机》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115617700A (en) * 2022-12-19 2023-01-17 华东交通大学 Test case design and generation method and system based on relational analysis
CN115617700B (en) * 2022-12-19 2023-04-07 华东交通大学 Test case design and generation method and system based on relational analysis
CN116089317A (en) * 2023-04-10 2023-05-09 江西财经大学 Multipath testing method and system based on path similarity table and individual migration
CN116089317B (en) * 2023-04-10 2023-06-27 江西财经大学 Multipath testing method and system based on path similarity table and individual migration

Also Published As

Publication number Publication date
CN115248781B (en) 2022-12-27

Similar Documents

Publication Publication Date Title
CN115248781B (en) Combined test case generation method, device, equipment and readable storage medium
Aghdam et al. Text feature selection using ant colony optimization
US9058564B2 (en) Controlling quarantining and biasing in cataclysms for optimization simulations
US8700548B2 (en) Optimization technique using evolutionary algorithms
CN111144555A (en) Recurrent neural network architecture search method, system and medium based on improved evolutionary algorithm
CN109543247B (en) NSGA-II-based analog integrated circuit parameter optimization design method and device
Das et al. Multi-objective feature selection (MOFS) algorithms for prediction of liquefaction susceptibility of soil based on in situ test methods
CN110287179A (en) A kind of filling equipment of shortage of data attribute value, device and method
CN109390032B (en) Method for exploring disease-related SNP (single nucleotide polymorphism) combination in data of whole genome association analysis based on evolutionary algorithm
JP7137074B2 (en) Optimization calculation method, optimization calculation device, and optimization calculation program
Hamda et al. Multi-objective evolutionary topological optimum design
Lin et al. A new density-based scheme for clustering based on genetic algorithm
CN114862071B (en) Method, device and equipment for predicting reaming torque of horizontal directional drilling and storage medium
Huang et al. A grid and density based fast spatial clustering algorithm
Chen et al. Timing-driven X-architecture Steiner minimum tree construction based on social learning multi-objective particle swarm optimization
CN115408929A (en) Data processing method and device for tunnel driving construction prediction
CN114462294A (en) Two-stage agent model auxiliary parameter estimation method and system
CN115146702A (en) Transformer fault diagnosis method, medium and system
CN113554144A (en) Self-adaptive population initialization method and storage device for multi-target evolutionary feature selection algorithm
Flaherty et al. Distributed octree data structures and local refinement method for the parallel solution of three-dimensional conservation laws
Athènes et al. Multiple‐Replica Exchange with Information Retrieval
Soper et al. A combined evolutionary search and multilevel approach to graph partitioning
CN116386790B (en) Conductivity evaluation method, device, electronic equipment and readable storage medium
Sawai et al. Effects of hierarchical migration in a parallel distributed parameter-free GA
CN110020003A (en) Selection one by one to the project of set

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant