CN115617700B - Test case design and generation method and system based on relational analysis - Google Patents
Test case design and generation method and system based on relational analysis Download PDFInfo
- Publication number
- CN115617700B CN115617700B CN202211631619.3A CN202211631619A CN115617700B CN 115617700 B CN115617700 B CN 115617700B CN 202211631619 A CN202211631619 A CN 202211631619A CN 115617700 B CN115617700 B CN 115617700B
- Authority
- CN
- China
- Prior art keywords
- case
- relation
- parent
- cases
- elements
- 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.)
- Active
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 88
- 238000004458 analytical method Methods 0.000 title claims abstract description 67
- 238000000034 method Methods 0.000 title claims abstract description 67
- 238000013461 design Methods 0.000 title claims abstract description 21
- 238000012545 processing Methods 0.000 claims abstract description 48
- 238000004422 calculation algorithm Methods 0.000 claims abstract description 21
- 230000006798 recombination Effects 0.000 claims description 32
- 238000005215 recombination Methods 0.000 claims description 32
- 238000009402 cross-breeding Methods 0.000 claims description 19
- 230000035772 mutation Effects 0.000 claims description 5
- 238000009395 breeding Methods 0.000 claims description 4
- 230000001488 breeding effect Effects 0.000 claims description 4
- 230000008521 reorganization Effects 0.000 claims 1
- 238000012216 screening Methods 0.000 claims 1
- 230000006870 function Effects 0.000 abstract description 47
- 230000033458 reproduction Effects 0.000 description 67
- 239000011159 matrix material Substances 0.000 description 7
- 230000001174 ascending effect Effects 0.000 description 5
- 238000003491 array Methods 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 3
- 230000007547 defect Effects 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 230000000644 propagated effect Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 2
- 238000002474 experimental method Methods 0.000 description 2
- 239000000463 material Substances 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 208000035657 Abasia Diseases 0.000 description 1
- 241000229537 Moxostoma Species 0.000 description 1
- 230000001364 causal effect Effects 0.000 description 1
- 230000000295 complement effect Effects 0.000 description 1
- 238000011981 development test Methods 0.000 description 1
- 208000021267 infertility disease Diseases 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 238000005065 mining Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000035755 proliferation Effects 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 230000000717 retained effect Effects 0.000 description 1
- 238000013522 software testing Methods 0.000 description 1
- 238000003860 storage Methods 0.000 description 1
- 238000011282 treatment Methods 0.000 description 1
- 239000002759 woven fabric Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/12—Computing arrangements based on biological models using genetic models
- G06N3/126—Evolutionary algorithms, e.g. genetic algorithms or genetic programming
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Biophysics (AREA)
- Life Sciences & Earth Sciences (AREA)
- Health & Medical Sciences (AREA)
- Evolutionary Biology (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Artificial Intelligence (AREA)
- Data Mining & Analysis (AREA)
- Physiology (AREA)
- Genetics & Genomics (AREA)
- Quality & Reliability (AREA)
- Biomedical Technology (AREA)
- Computational Linguistics (AREA)
- Computer Hardware Design (AREA)
- Evolutionary Computation (AREA)
- General Health & Medical Sciences (AREA)
- Molecular Biology (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The invention provides a test case designing and generating method and a system based on relational analysis, wherein the method comprises the following steps: acquiring function requirements and a processing mode of a program to be tested, and performing relation analysis on variables in the program to be tested according to the function requirements and the processing mode to obtain a relation between input variables and a relation between the input variables and output variables; designing a plurality of relation use cases according to the relation between the input variables and the output variables to obtain a relation use case set; and generating a progeny case according to a preset ecological reproduction test case algorithm and the test case set, and performing auxiliary test on the program to be tested according to the progeny case. The method for designing and generating the test cases based on the relational analysis solves the problems that the test cases obtained in the traditional mode are difficult to be suitable for researching and analyzing programs with large input data quantity and complex functions, and meanwhile, a large number of test cases with diversity and corresponding functional requirements can be designed in an auxiliary mode, and the burden of manual design is greatly reduced.
Description
Technical Field
The invention relates to the technical field of software testing, in particular to a method and a system for designing and generating a test case based on relational analysis.
Background
The software tester executes the test case to verify the software function and tests to find out the software defect. Designing an efficient, reasonable and complete test case set is the key work of software function testing.
At present, the test case design has many theoretical methods, such as an equivalence class method, a boundary value method, a causal graph method, a decision table method and the like. The equivalence class method and the boundary value method are the most commonly used methods. However, for many programs with relatively complex input, output and requirements, the equivalence class method is difficult to make equivalence division, and the internal boundary values and special values are also difficult to be fully analyzed, so that an efficient, reasonable and complete test case set is difficult to obtain. For example, for a program for searching for a maximum value, the input is an array with a variable length, and the input cannot be divided into equivalent classes by using an equivalent class method, and all boundary values cannot be derived and analyzed. For another example, for a binary search procedure, it is difficult to perform an equivalent division on a value or an array to be searched by using an equivalence class method, and all boundary values cannot be derived and analyzed. Therefore, for many relatively complex software functions, certain defects exist when an equivalence method and a boundary value method are used for research and analysis, so that a reasonable and complete test case is difficult to design, and a test case design method capable of deeply and comprehensively analyzing complex program functions, inputs and outputs is urgently needed.
On the other hand, for programs with large input data volume and complex functions, such as course arrangement in colleges and universities, production planning, text mining and the like, if all latent defects are to be tested as much as possible, a large number of use case development tests need to be designed. Because the input data volume is large, a certain amount of time is needed for manually designing a small amount of use cases, and it is very difficult to design a large amount of test use cases which have diversity and can correspond to functional requirements.
There are also many methods for automatically generating test cases, however, many of these methods are to randomly select or optimally combine within a limited range or under a limited condition, or to analyze codes and the like to generate test cases. These automatic generation methods do not have the functional requirements of the analysis program and the ability to process the way at all. For example, for the next day program NextDate (y, m, d), the function of calculating and outputting the date (y 2, m2, d 2) of the next day for inputting the date year, month and day (y, m, d) is divided into: three types of treatments for the middle of the month, the end of the month, and the date of absence (e.g., 2 months 30). The equivalence class division can be made for the input (y, m, d) according to the functional requirements and processing mode: the months can be divided into big months (1,3,5,7,8,10,12), small months (4,6,9,11) and february (2); the years can be divided into leap years (2016,2000) and peaceful years (1900,2015); the daily score is (1-27,28,29,30,31). However, the computer does not have human intelligence to understand the functional requirements, and cannot automatically classify the equivalence classes for the dates. This analysis can only be made by the tester or programmer according to the functional requirements and the nature of the input date. Of course, the manually designed year, month and day data can be input into the automatic case generation system, and the system randomly combines or combines the input data according to the manually set requirements to obtain cases, so that some manual burdens are reduced. Therefore, the method is a feasible method for inputting the manually designed key data or use cases meeting the functional requirements and generating a large number of use cases through system assistance.
Disclosure of Invention
Based on the above, the invention aims to provide a test case design and generation method and system based on relational analysis, so as to solve the problem that the traditional design method is difficult to deeply and comprehensively analyze complex programs, and a reasonable, effective and comprehensive test case set can be designed; meanwhile, the system can automatically generate and design a large number of auxiliary test case sets which have diversity and correspond to functional requirements, and the burden of manual design is greatly reduced.
According to the test case design and generation method based on the relational analysis, the method comprises the following steps:
acquiring function requirements and a processing mode of a program to be tested, and performing relation analysis on variables in the program to be tested according to the function requirements and the processing mode to obtain a relation between input variables and a relation between the input variables and output variables;
designing a plurality of relation use cases according to the relation between the input variables and the output variables to obtain a relation use case set;
and inputting the relation case set to generate a subsequent generation case set according to a preset ecological reproduction test case algorithm.
In summary, according to the method for designing and generating test cases based on the relational analysis, through the analysis of the function and input complex program development relations, the relations can comprehensively cover the function requirements and the processing modes, so that the efficient, reasonable and complete test cases can be designed, the latent, difficult-to-find program bugs can be found out, and the capability of testers and programmers in designing the test cases can be improved. For a complex program with large input data amount, after a relation case set is designed, a large number of descendant case sets with relation characteristics and diversity can be obtained through multiple rounds of reproduction, recombination and variation by relying on the proposed ecological reproduction algorithm and taking the relation case set as the basis, and the complex program with large input data amount can be comprehensively and effectively tested in an auxiliary manner.
Further, the step of obtaining the function requirement and the processing mode of the program to be tested, and performing relationship analysis on the variables in the program to be tested according to the function requirement and the processing mode to obtain the relationship between the input variables and the output variables comprises:
acquiring a whole input set corresponding to the program to be tested, and acquiring input variables and effective input conditions for representing the whole input set according to the whole input set;
analyzing the value types of the single variables and various relations among the input variables by taking the input variables and the effective input conditions as analysis objects according to the functional requirements and the processing mode;
and inputting all input variables into the program to be tested respectively to obtain output variables, and corresponding the output variables to the input variables according to the function requirements to obtain the relation between the output variables and the input variables.
Further, the step of inputting the relational case set to generate a descendant case set according to a preset ecological reproduction test case algorithm includes:
inputting the relational use case setAnd initializing the parent setAnd for the parent setTo carry outAnd repeating the loop again to reproduce the offspring use case set.
Further, the inputting the relational use case setAnd initializing the parent setAnd for the parent setTo carry outThe step of repeating the loop for the second time to reproduce the offspring case set comprises the following steps:
for the parent setPerforming cross propagation to obtain a primary set, then performing individual recombination on the primary set to obtain a recombined set, and performing individual variation on the recombined set to obtain a variant set;
taking the obtained variation set as a child set in the iterative reproduction, and calculating to obtain the similarity between the child set and a parent set in the reproduction;
and taking the filial generation set in the iterative reproduction as a parent set in the next reproduction to perform cross reproduction, individual recombination and individual variation again, and outputting the filial generation sets in the iterative reproduction and the corresponding similarity.
Further, the pair of the parent setThe step of performing cross breeding to obtain a primary set comprises the following steps:
collecting the parentEach parent use case inRandomly matching another parent caseSo that two different parent cases can exchange partial elements to obtain two sub cases.
The parent setEach parent use case inRandomly matching another parent use caseSo that two different parent cases can exchange partial elements, and the step of obtaining two sub cases comprises:
acquiring a random number, and calculating according to the random number and a parameter corresponding to the current cross reproduction to obtain the number of elements exchanged in the current cross reproduction by the two relation cases;
and calculating the number of interchangeable elements of the two relation cases in the current cross reproduction according to the following formula:
wherein,representing the number of elements that the two relational use cases interchange in the current cross-breeding,andrespectively represent the lengths of two relational use cases,denotes the firstThe parameters of the secondary cross-breeding are,represents a random number and;
obtaining parameters corresponding to the current cross breeding according to the following formula:
wherein,the initial cross-breeding parameters are expressed,a、b、cthree constant parameters are represented;
the step of carrying out individual recombination on the primary set to obtain a recombined set comprises the following steps:
and acquiring the length of each nascent case in the nascent set, and interchanging the positions of two elements of each nascent case according to the length and the random number to obtain a recombined set.
The step of performing individual variation on the recombination set to obtain a variation set comprises:
and carrying out variation on the elements in the recombination set according to a preset value range.
Further, the step of mutating the elements in the recombination set according to a preset value range includes:
if the elements in the relation case set are numerical value types, calculating to obtain a current variation value according to the numerical values of the elements to be varied in the recombination set and the control parameters of the current individual variation degree, and carrying out individual variation on the elements to be varied according to the current variation value to obtain a variation-completed numerical value, wherein the variation-completed numerical value range is the same as a preset value range;
if the elements in the relation case set are of non-numerical type, the preset value range is selectedRandomly selecting an element to replace the element to be mutated to complete individual mutation.
Further, if the element in the relationship case set is a numerical value type, calculating a current variation value according to a numerical value of the element to be varied in the recombination set and a control parameter of a current individual variation degree, so as to perform individual variation on the element to be varied according to the current variation value, thereby obtaining a variation-completed numerical value, where a variation-completed numerical range is the same as a preset value range, including:
obtaining the current variance value according to the following formula:
wherein,which is indicative of the current variance value,is a control parameter of the current individual variation degree,the absolute value of the element to be varied is indicated.
Further, the step of taking the obtained variant set as a child set in the current iterative reproduction and calculating to obtain the similarity between the child set and a parent set in the current reproduction includes:
calculating the similarity between the parent set and the child set in the reproduction according to the following formula:
wherein,denotes the firstThe similarity between the parent set and the child set in the sub-iterative multiplication,denotes the firstThe set of parents in the secondary iteration breeding,is shown asThe set of children in the sub-iterative multiplication,is shown asThe number of use cases in the child set in the sub-iterative multiplication,representing the first in a parent setIndividual caseAnd the warpThe obtained filial generation set is usedExample (B)The similarity of (c).
Further, the method further comprises:
if the elements in the relation case set are numerical value types, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent caseAnd its sub-case x,representing a parent caseTo middleThe number of the elements is one,number of presentation sub-case xThe number of the elements is one,the length of the use case is represented,a parameter representing the degree of initial variation;
if the elements in the relation case set are of non-numerical type, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent caseAnd its sub-case x,the weight parameter is represented by a weight value,representation for judging parent use caseTo middleAn elementAnd sub-case xAn elementWhether or not the same function is used,represents an elementMatch all elements in the sub-case x ifIn presence of elements and use casesIf the two are the same, 1 is returned, otherwise 0 is returned.
According to the embodiment of the invention, the system for designing and generating the test case based on the relational analysis comprises the following components:
the system comprises a relation analysis module, a processing module and a processing module, wherein the relation analysis module is used for acquiring the function requirement and the processing mode of a program to be tested, and carrying out relation analysis on variables in the program to be tested according to the function requirement and the processing mode to obtain the relation between input variables and the relation between the input variables and the output variables;
the case set generating module is used for designing various relation cases according to the relation between the input variables and the output variables to obtain a relation case set;
and the case reproduction module is used for inputting the relational case set so as to generate a offspring case set according to a preset ecological reproduction test case algorithm.
Drawings
Fig. 1 is a flowchart of a test case designing and generating method based on relationship analysis according to a first embodiment of the present invention;
fig. 2 is a flowchart of a test case designing and generating method based on relationship analysis according to a second embodiment of the present invention;
FIG. 3 is a detailed diagram of step S106 in the second embodiment of the present invention;
fig. 4 is a flowchart of a test case designing and generating method based on relationship analysis in the third embodiment of the present invention.
The following detailed description will further illustrate the invention in conjunction with the above-described figures.
Detailed Description
To facilitate an understanding of the invention, the invention will now be described more fully with reference to the accompanying drawings. Several embodiments of the invention are shown in the drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the term "and/or" includes any and all combinations of one or more of the associated listed items.
Referring to fig. 1, a flowchart of a test case designing and generating method based on relationship analysis according to a first embodiment of the present invention is shown, where the method includes steps S01 to S03, where:
step S01: acquiring function requirements and a processing mode of a program to be tested, and performing relation analysis on variables in the program to be tested according to the function requirements and the processing mode to obtain a relation between input variables and a relation between the input variables and output variables;
it should be noted that the processing mode refers to various specific processes that the program to be tested should perform to meet the functional requirements. The meaning of the variable in the relation analysis comprises objects related to functional requirements, such as positions, polygons, curriculum schedules, dormitories, teaching buildings and the like, and analyzable relations, such as the inside, the outside and the edges of the polygons, comprise a plurality of objects (such as red chessmen and bus stations), wherein in the process of analyzing various relations in input and output, each relation needs to be completely analyzed, namely various conditions of the relations are analyzed, so that test holes can be avoided, and codes can be covered. For example, when analyzing the relationship between the value k to be examined and the array element ai, i ∈ [1,n ] is considered, the boundary values a1 and an of ai are treated with emphasis, and the relationship between k and a1 and the relationship between k and an are also analyzed.
Step S02: designing a plurality of relation use cases according to the relation between the input variables and the output variables to obtain a relation use case set;
it can be understood that, for a general program to be tested, through reasonably and completely analyzing input and output, a sufficient kind of relation case set can be designed according to the obtained relation. The relation case set can comprehensively embody the function requirements and various processing modes in a data form, and can effectively verify whether the program correctly and comprehensively realizes the function requirements. The code of the program to be tested is usually reasonable on the main body, so that the coverage rate of the relation case set on the general code can achieve complete coverage, namely, the relation between various variables obtained in relation analysis can be completely covered by the relation case set through design.
Step S03: and inputting the relation case set to generate a descendant case set according to a preset ecological reproduction test case algorithm.
However, if the core function of the program to be tested and the code thereof are complicated, whether a Bug exists in the code or not, several bugs are hidden, and where the Bug is hidden respectively, are unknown. To ensure that all the latent bugs are found, more use cases are required to test for core functions and code. If the data volume input by the program to be tested is small, a programmer or a tester can design a batch of extension cases by combining and changing according to various analyzed relationships based on the relationship case set. If the input of the program to be tested is the condition of large data quantity such as a long array, a plurality of arrays or a matrix, the new addition of a large number of use cases is very difficult and time-consuming, based on the condition, the relation use case set is taken as a main part, a large number of later-generation use case sets are obtained through an improved algorithm for auxiliary testing, and the latent Bug is easy to find out.
Example 1: taking the maximum value searching program largest (int [ ] data) as an example; the specific implementation steps are as follows:
functional requirements are as follows: finding out the maximum element in the input array data, and returning.
And step one, reasonably and completely analyzing the relation of the program to be tested according to the functional requirements and the processing mode, and analyzing the relation among input variables and the relation between output and input.
1) The set of valid inputs for the program as a whole is expressed in terms of variables and conditions as: data = (d 1, d2, …, di, …, dn), condition: n > =1.
2) Analyzing relationships between input variables
Kinds of individual variables: the single di has no direct relation with the processing mode, the equivalence class division cannot be carried out, and the boundary value cannot be analyzed. Using the condition n > =1 for n, it can be analyzed that: general case n >1; boundary value n =1 (input an array of one element); special value n =0 (condition for valid input is not satisfied, invalid case can be designed).
Relationship of di and dj: the values di > dj, di < dj and di = dj, and the positions i > j and i < j. These relationships are weakly related to the processing mode of finding the maximum value of the array, have no direct relationship, and cannot be used for designing a case, so are discarded.
The relationship between multiple variables is similar to the relationship between two variables, and analysis is not required to be expanded.
Relationship of the entire input array: too many n elements make analysis difficult to be performed by hands, and analysis is not expanded at all.
3) Analyzing relationships of outputs and inputs
The relationship between the output maximum value m and the input data is as follows: m corresponds to the maximum value dt in the input array, the relationship dt > = di exists, i belongs to [1,n ] and i ≠ t, and di is other elements except dt in the array. The relationship dt is actually the relationship of the entire array in step two.
By analyzing it completely, dt > = di can be classified as: 1) The position t of the maximum value dt is within a range from t epsilon [1,n ], t =1 and t = n are boundary values, and 1-t-n is a general case; 2) dt > di, i.e. dt is the only maximum in the array; 3) dt = dj, some elements dj are equal to the maximum, i.e. there are several equal maximum values (needed if the functional requirement is to find the number of maximum values), where the number of elements dj is in the range of [1,n-1].
And step two, designing a test case according to various relationships obtained by analysis.
Depending on the special value n =0 and the boundary value n =1, use cases { } (null array, invalid use case), and use cases {1} of a single element can be designed. Equivalence classes: and n >1, the array length of the general case is larger than 1.
From the boundary values t =1 and t = n, use cases {9,4,7,3,5,1} and {7,5,8,3,0,6,9} can be designed, the maximum values of which are at the first element and the last element, respectively. The use cases {6,4,9,8,1,7,2} can be designed by general case 1-t-woven fabric with the maximum value in the array.
According to the relationship: dt = dj, some elements dj are equal to the maximum value, the number of dj is in the range of [1,n-1], and use cases {1,5,9,6,9,4}, {9,6,5,9,3,9,1,2} and {9,9,9,9,9,9} can be designed, wherein the number of the elements equal to the maximum value among the three use cases is 1, a plurality of elements, and n-1 elements respectively. The actual code does not necessarily need to select the 3 cases, and certainly, in order to ensure the completeness of the test, the types of the cases are comprehensive and better. Generally, in the relationship analysis, various relationships need to be analyzed to avoid test vulnerabilities.
If the test cases are added to ensure the test result is completely consistent, some cases can be continuously designed according to all the relationships analyzed above. For example, {19,8,4,9, -10,5,11}, {8,19, -3,6,2, -5,1} and {1,5,19, -6,7,3,15,2} may be designed using the relationship of the position t of the maximum, with their maximum 19 at the 1 st, 2 nd and 3 rd positions, respectively. Of course, step three may also be run to generate more use cases.
And step three, generating a progeny use case through an ecological reproduction algorithm to assist in testing.
Step two, designing 8 relation cases, wherein { } and {1} are used for processing the two special cases by a test program; the other 6 kinds of use cases have relationship diversity, are used for testing the main code of the program, and can be used as a relationship use case set. Preliminarily setting (v 1, v 2) = (-9,19), after selecting the numerical similarity, reading the designed relation case set (except { } and {1} in the second step) by the ecological reproduction program, and starting to circulate the reproduction process for 5 times. The read relation case set is sorted as follows:
{9,4,7,3,5,1}
{7,5,8,3,0,6,9}
{6,4,9,8,1,7,2}
{1,5,9,6,9,4}
{9,6,5,9,3,9,1,2}
{9,9,9,9,9,9}
after circular propagation, the number of offspring in each round is (24,48,48,48, 48), and the paternal-child similarity in each round is (0.93,0.91,0.89,0.92,0.91). The first round contained 4 sets of descendant use cases, one of which is shown below.
{9,4,7,3,5,2}
{6,5,8,3,0,6,11}
{9,4,9,10,1,7,2}
{1,5,7,6,9,8}
{9,9,5,9,3,9,2,2}
{8,9,10,9,9,9}
The length of the generated offspring use case is the same as that of the relation use case, wherein the bold elements are changed in numerical value after one round of reproduction, and the other elements are not changed. The third round contains 8 sets of descendant use cases, one of which is shown below.
{9,4,8,3,5,2}
{5,6,8,3,0,6,11}
{9,4,6,10,1,7,2}
{1,5,6,7,9,8}
{9,7,5,10,3,2,4,5}
{10,8,9,9,7,5}
The fifth round contained 8 sets of offspring use cases, one of which is shown below.
{9,4,8,2,5,2}
{5,6,8,2,0,6,11}
{9,4,6,10,1,7,2}
{1,4,6,7,9,8}
{9,7,5,10,2,2,4,5}
{10,9,9,9,7,5}
Comparing the original relation case set with the generated partial descendant case sets, it can be seen that most relation case elements are retained during the first reproduction, and after the third and fifth reproductions, the approximation degree of the descendant sets and the relation sets is reduced, and new diversity is embodied. The offspring use cases of each round of reproduction will gradually increase new changes, and the characteristics from the relationship analysis gradually decrease. Therefore, the descendant cases of each round represent input types with different characteristics, and the cases are used for assisting the expansion test of the relational case set to obtain ideal test performance.
Example 2: two-point search program search (int [ ] array, int k)
Functional requirements are as follows: finding out whether k values to be found are in the elements of the array arranged in the ascending order, and if the elements are found, returning the positions of the elements; if no value of k is found, return to-1.
And step one, reasonably and completely analyzing the relation of the program to be tested according to the functional requirements and the processing mode, and analyzing the relation among input variables and the relation between output and input.
1) The set of valid inputs for the program as a whole is expressed in terms of variables and conditions as: array = (a 1, a2, …, ai, …, an), wherein the condition: if i < j, then ai < aj; n > =1.
2) Analyzing relationships between input variables
Kinds of individual variables: the single ai or k has no direct relation with the processing mode, the equivalence class division cannot be carried out, and the boundary value cannot be analyzed. Using the condition n > =1 for n, it can be analyzed that: general case n >1; boundary value n =1 (input an array of one element); special value n =0 (invalid input).
The relationship of the two variables includes: the relationship of ai and aj; and the relationship of k and ai.
The relationship between ai and aj is already clear in the input condition, if i < j, then ai < aj exists, which is a precondition for inputting an ascending array required by the functional requirement, and no expansion analysis is needed.
In the relationship between k and ai, i belongs to [1,n ], a1 and an are boundary values, and the relationship between k and a1 and an needs to be analyzed. The relation can be completely analyzed by combining the searched functional requirements and processing modes: k = ai found, k ≠ ai not found; k = a1, k < a1 is found to be smaller than the minimum value a 1; k = an is found, k > an is greater than the maximum value an; wherein k < a1 and k > an are special cases in the processing mode of the binary search program, and the value k to be searched is out of the numerical range of the array.
3) Analyzing relationships of outputs and inputs
If the k value is found, the output result is the position i of the found element, and the corresponding relation is as follows: k = ai, including boundary cases k = a1 and k = an. If no k value is found, the output result is-1, and the corresponding complete analysis is: k is not equal to ai; boundary cases k ≠ a1 and k ≠ an are included. In the boundary case, k > a1 and k < an do not correspond to a specific processing mode and should be discarded, so that the relation to be tested is k < a1 and k > an. The relationship analyzed in step three is the same as that of k and ai in step two.
And step two, designing a test case according to various relationships obtained by analysis.
Depending on the special value n =0 and the boundary value n =1, use cases { } (null array, invalid use case), and use cases {5} of a single element can be designed. General conditions are as follows: and n >1, the array length of the general case is larger than 1. The array is arranged in ascending order, and a plurality of use cases can be designed: {1,3,6,7,9},{5,6,8,27,32,46,50,68, 83,99}.
And according to the relation between k and ai in the second step, designing k = -1,5,8 for the array {5}. For the array {1,3,6,7,9}, use cases of k = -1,1,5,6,9,13, etc. may be designed. For the second array, use cases of k =2,5,27,48,99,100, etc. can be designed.
The use case was designed with 3 k values except for {5}, and for two other arrays, each array has 6 k values, for a total of 16 use cases. The experiment sets 5 code versions with different bugs for the binary search code, the test operation relation case can completely cover the code, and the 5 bugs can be found.
If the test case is added, k = -5,2,3,7,8,19 can be added to the array {1,3,6,7,9}, and k = -3,6,7,8,30,32,46,50,55,68,70,83,110 can be added to another array by using the relation between k and (a 1, ai, an). And designing a plurality of well-ordered arrays, and designing a plurality of k values for each array by applying the relation.
And step three, generating a progeny use case through an ecological reproduction algorithm to assist in testing.
The binary search program can manually design a large number of use cases depending on the relation, the use cases can be sufficiently and completely covered by codes of the program, and generally, a multiplication algorithm does not need to be operated to generate the use cases. In addition, the input array of the program is an array which is arranged in an ascending order and is not repeated, so that it is difficult to directly generate a large number of required use cases. If the elements in the ascending array are required to be not repeated, range parameters and the like can be reasonably set, the repeated degree of the elements is reduced, and finally, a small number of repeated elements are manually removed or modified.
Example 3: the program to be tested is a chess cannon walking program.
Functional requirements are as follows: in the process of the chess game, a player selects a cannon at a position A and clicks a certain position B on a chessboard; the program analyzes the results of this step-by-step shot: walking, cannon fighting enemies, cannon fighting commander wins chess, and if cannon A can not walk to position B, the user needs to be prompted.
And step one, reasonably and completely analyzing the relation of the program to be tested according to the functional requirements and the processing mode, and analyzing the relation among input variables and the relation between output and input.
1) The set of valid inputs for the program as a whole is expressed in terms of variables and conditions as: position of a and B (xA, yA, xB, yB) and current piece on the board (q 1, q 2.. Qn) qi = (namei, xi, yi). The position x on the chess game belongs to the field of 0,8, and y belongs to the field of 0,9. The name of the red chess belongs to the field of 1,7 and represents 7 chess pieces (the red cannon is 2, the red soldier is 1, the black chess piece is with a minus sign, the black cannon is-2, and the black pawn is-1).
2) Analyzing relationships between input variables/objects
Kind of individual object: the chess has no requirement on the position A of the cannon and no requirement. Kind of the position B: empty chessman and chessman (the former, the enemy and the enemy will be commander).
Relationship of two objects: the relationship between A and B is A = B and A! = B (A and chess, B and chess have no relationship). And A = B indicates that AB is overlapped and cannot walk, so that an invalid case can be designed. A! = B then AB constitutes the line segment, and the cannon can walk when the AB line segment is horizontal or vertical according to the functional requirement (chess rule), and can not walk when being oblique line, there is the relation: transverse, longitudinal and diagonal.
According to the functional requirements, the relationship between the AB line segment and the chess game: there are 0 (walkable), 1 (fireable) or more chessmen (not walkable) on AB.
3) Analyzing relationships of outputs and inputs
The outputs are four: walking, shooting with a cannon and shooting with a general cannon cannot walk. Relationship of walking to input: AB is transverse or longitudinal, and AB is devoid of subunits, and B is devoid of subunits. Relationship of the cannon to the input: AB is horizontal or vertical, and AB is 1 son, and B is enemy (or enemy general). Too many cases of incapability of walking are caused, and the analysis is complex and inconvenient.
Previously analyzed are 3 types of relationships: the direction of AB, the number of chessmen between AB and the condition of B point. The 3 kinds of relations are completely analyzed, namely complement completion: AB is horizontal, longitudinal and oblique; 0 seed, 1 seed and majority seed between AB; b is blank, the Chinese character 'ji' square, enemy square and general of enemy.
The relationships analyzed in 2) and 3) above are basically consistent, and 2) a special relationship of a = B is analyzed, so that a programmer may ignore the fact to write code and result in Bug, and thus such a use case is required.
And step two, designing a test case according to various relationships obtained by analysis.
An invalid case can be designed according to A = B: cannon 2 is at a = (3,7) and purpose B = (3,7). The chess game is a 9 x 10 matrix, the element value is 0 to indicate null, and the position element value of the chessmen is the name of the chessman. The use case focuses on the value of AB, and some chess piece names are randomly arranged in the chess game. Because the chess game matrix occupies space, only one specific chess game case data is shown below, and the matrix parts of the other cases are omitted.
The variable relationships are as follows: 3 in the AB direction, 3 in the middle of the AB direction and 4 in the B point. Design cases need to cover these cases reasonably completely. Design example of cannon attack enemy a: gun-2 has soldiers 1 in A = (2,2), purpose B = (2,6), AB is longitudinal, and only position C (2,3) has pawns-1 on the AB line segment. The chess game of use case a takes the following 9 x 10 matrix.
Chess game 3 4 5 6 7 50 3
0 0 0 0 0 0 0 0 0
0 2 0 0 0 0 4 2 0
1 0 1 0 1 0 1 0 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
-1 0-1 0-1 0-1 0-1
0 0-2 0 0 0 0-2 0
0 0 0 0 0 0 0 0 0
-3-4-5-6-7-6-5-4-3
Cannon enemy case b: the cannon 2 has pawns-1 at A = (1,3), a goal B = (4,3), an AB is transverse, and a pawn-1 is only at a position C (2,3) on an AB line segment. Space-limited, use case b and the following use cases, the board game is partially omitted. The shooting enemy strictly meets 3 small conditions: AB transverse or longitudinal and AB inter 1 and B enemy. Thus this relationship is covered by cases a and b.
When the use cases of the enemy commander are designed by the cannon, 1 longitudinal (or transverse) use case of the enemy commander can be designed manually because the previous use cases a and b already cover the processing mode of judging the transverse direction and the longitudinal direction. Shooting enemy and commander case c: the red cannon 2 has a chessman black elephant-1 at A = (4,3), the purpose B = (4,0) is enem general-7, and only the position C (4,2) on the AB longitudinal line segment.
Example of walking d: black gun-2 has no chess pieces on the horizontal line segment AB with A = (7,2), the purpose B = (4,2) is empty 0, and AB. Walking should strictly meet 3 minor conditions: AB transverse or longitudinal and AB internodal and B infertile. Thus case d can cover this relationship. The horizontal or vertical relationship is covered by the previous use cases a-c.
Case e, unable to walk: red cannon 2 can not move in the oblique direction of AB when A = (4,5) and the purpose B = (6,7) is empty 0. If f, the black gun-2 is in A = (3,5), and the purpose B = (6,5) is that the black pawn-1, AB is transverse but the chessman cannot move at point B. In case g, the red cannon 2 has a red horse 4 at A = (4,3), the purpose B = (4,6) is empty 0, and C = (4,5) on an AB longitudinal line segment, so that the person cannot walk. The 3 cases correspond to factors which cannot be walked in the 3 types of relations: oblique, with chessmen in the middle, with chessmen at point B.
Case h which cannot be fired: black gun-2 is in A = (6,3), purpose B = (5,7) is empty 0, AB cannot be shot obliquely. Use case i: red cannon 2 has two chessmen between A = (0,0), the purpose B = (4,0) is that enem general-1, AB transverse direction position C = (2,0) has black elephant-5 and position D = (3,0) has black dragon-6, AB cannot cannon. Case j: black gun-2 is friend and cannot fire at A = (7,2), purpose B = (2,2) is black horse-4, AB transverse direction position C = (4,2) has black phase-5, AB chessman. The 3 cases correspond to the factors that cannot be shot in the 3 types of relations: oblique, 2 pieces in the middle and friend point B.
The above cases a-j and invalid case can completely cover all relations in the step one: 3 in the AB direction, 3 in the middle of the AB direction and 4 in the B point. The logic complexity of the shot-shooting-running code is not high, 4 code versions with different bugs are set through experiments, the test operation relation case can completely cover the code, and the 4 bugs can be found out. If the time is sufficient, the combination can be arranged according to all the relations to obtain 3 × 3 × 4=36 use cases.
And step three, generating a progeny use case through an ecological reproduction algorithm to assist in testing.
The previously designed cases of a-j are 10, and the analysis is focused on A, B and the chessmen in the middle of AB. However, in the whole chess software, a plurality of small programs such as horse walking, soldier walking, car walking and the like exist, and enough chess game matrix cases need to be obtained through ecological reproduction to develop sufficient tests. Because the number of the chess pieces on the chessboard is limited by rules, the value range is set to be [ -7,7] before the reproduction algorithm is operated, the individual variation parameters are reduced, and the cross reproduction and the individual recombination are mainly used to obtain the offspring use cases. The obtained use case set can obtain a chess game matrix use case which accords with the actual chess playing by simply modifying a small amount of data.
In summary, according to the method for designing and generating test cases based on the relational analysis, through analyzing the function and the input complicated program development relations, the relations can comprehensively cover the function requirements and the processing modes, so that the efficient, reasonable and complete test cases can be designed, latent and difficult-to-find program bugs can be found out beneficially, and testers and programmers can be helped to improve the capability of designing the test cases. For a complex program with large input data amount, after a relation case set is designed, a large number of descendant case sets with relation characteristics and diversity can be obtained through multiple rounds of reproduction, recombination and variation by relying on the proposed ecological reproduction algorithm and taking the relation case set as the basis, and the complex program with large input data amount can be comprehensively and effectively tested in an auxiliary manner.
Referring to fig. 2, a flowchart of a test case designing and generating method based on relationship analysis according to a second embodiment of the present invention is shown, where the method includes steps S101 to S106, where:
step S101: acquiring a whole input set corresponding to the program to be tested, and acquiring input variables and effective input conditions for expressing the whole input set according to the whole input set;
step S102: analyzing the value types of the single variables and various relations among the input variables by taking the input variables and the effective input conditions as analysis objects according to the functional requirements and the processing mode;
step S103: inputting all input variables into the program to be tested respectively to obtain output variables, and corresponding the output variables to the input variables according to the function requirements to obtain the relation between the output variables and the input variables;
it should be noted that the set of input variables and valid input conditions is to correspond exactly to the range of all inputs of the program to be tested.
Furthermore, variables and conditions of the input set are taken as objects, the functions of the software are reasonably analyzed in combination with the requirements and the processing modes of the software, and each analyzed variable relation is corresponding to the function requirements and the processing modes.
In the relational analysis, the category of a single variable in the input is analyzed, then the relation between two input variables is analyzed, and the relation between a plurality of variables and the relation of the whole input are analyzed subsequently, so that all the variable relations related to the function requirements and the processing modes in the input space are analyzed comprehensively.
Step S104: designing a plurality of relation cases according to the relation between the input variables and the output variables to obtain a relation case set;
step S106: inputting the relational use case setAnd initializing the parent setAnd for the parent setTo carry outAnd repeating the loop for several times to obtain the descendant case set.
Referring to fig. 3, a detailed diagram of step S106 in the present embodiment is shown, where step S106 includes step S1061 to step S1063, where:
step S1061: for the parent setPerforming cross propagation to obtain a primary set, then performing individual recombination on the primary set to obtain a recombined set, and performing individual variation on the recombined set to obtain a variant set;
in the process of cross-breeding the parent set, first, the parent set Z is set d Each relation use case in the relation use cases is randomly matched into another relation use case, so that different relation use cases carry out partial element interchange, and two sub use cases are obtained.
Specifically, firstly, a random number r is obtained, and the number of elements exchanged in the current cross reproduction by the two relation cases is obtained through calculation according to the random number r and parameters corresponding to the current cross reproduction;
and calculating the number of the interchange elements of the two relation cases in the current cross reproduction according to the following formula:
wherein m is 1 Representing the number of elements that the two relational use cases interchange in the current cross-breeding,andrespectively represent the lengths of two relation use cases,denotes the parameter of the d-th cross-breeding, r denotes a random number and;
obtaining the parameters corresponding to the current cross breeding according to the following formula:
parameter in (1)Is fixedly arranged asIn general, the first cycle of multiplication is carried out without modification,Is the initial cross-breeding parameter. The position of each exchanged element is also determined by a random numberTo be determined. Generally, the number of the primary cases obtained by each multiplication is equal to the number of the parent cases. The number of the first three breeding descendants needs to be considered because the descendants are similar to the relational case setAnd (5) doubling. The parameters of the first three times of reproduction are generally set asDefault setting。
Further, in the process of performing individual recombination on the obtained primary sets, firstly, the lengths of the primary sets need to be obtained, and the positions of two elements in each primary set are interchanged according to the lengths of the primary sets and random numbers; individual recombination representation in use casesSelf-selecting two elements to interchange position and interchange timesInterchanging the positions of two elements by random numbersAnd (5) determining. Parameters of recombination timesIs calculated byLike
Furthermore, in the process of performing individual variation on the obtained recombination set, firstly, an input type of an element in a relationship case set needs to be detected, if the element in the relationship case set is a numerical value type, a current variation value is obtained by calculation according to a numerical value corresponding to an element to be varied in the recombination set and a control parameter of a current individual variation degree, so that the element to be varied is subjected to individual variation according to the current variation value to obtain a variation-completed numerical value, and the variation-completed numerical value range is the same as a preset value range;
obtaining the current variance value according to the following formula:
wherein,which is indicative of the current value of the variance,and | x | represents the absolute value of the numerical value corresponding to the element to be mutated, which is the control parameter of the current individual mutation degree. The value of the mutated element is changed to. If out of rangeThen the random number is regeneratedCalculating again the variation valueTo ensureWithin the range. If the input type is integer, the right side of the formula needs to be rounded first and then the value of the element needs to be updated, that is, the value is。
If the elements in the relation case set are of non-numerical type, the preset value range is selectedRandomly selecting an element to replace the element to be mutated to complete individual mutation.
Step S1062: taking the obtained variation set as a child set in the iterative reproduction, and calculating to obtain the similarity between the child set and a parent set in the reproduction;
specifically, the similarity between the child set and the parent set in the reproduction is calculated according to the following formula:
wherein,is shown asThe similarity between the parent set and the child set in the sub-iterative multiplication,is shown asThe parent set in the sub-iterative multiplication,is shown asThe set of children in the sub-iterative multiplication,is shown asThe number of use cases in the child set in the sub-iterative multiplication,representing the first in a parent setIndividual caseAnd the warpThe propagated filial generation collective caseThe similarity of (2);
if the elements in the relation case set are numerical value types, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent caseAnd its sub-case x,representing a parent caseTo middleThe number of the elements is one,the second of the presentation sub-case xThe number of the elements is one,the length of the use case is represented,a parameter representing the degree of initial variation;
for example, a parent case of the sorting program is {11, 39, -8, 14, -25,5,9, 26, 53, -19,0, -13}, and the elements therein have the property of numerical magnitude, preferably numerical similarity s v Its length n =12.
If the elements in the use case are non-numerical in nature, it is not appropriate to use the similarity of the two previous numerical values. For example, the text paragraph of a certain use case of the string retrieval program is (Hello | My name's Xiaoming. I like playing football.), and it is looked up whether there is a string (ming) therein, and the number of occurrences is returned. For non-numerical use cases, the element similarity s can be calculated e The method specifically comprises the following steps:
wherein,representing a parent caseAnd itThe non-numerical similarity between the sub-cases x,a weight parameter is represented that is a function of,representation for judging parent casesTo middleEach elementAnd sub-case xAn elementWhether or not the same function is used,represents an elementMatch all elements in the sub-case x ifIn presence of elements and use casesIf the two are the same, returning to 1, otherwise, returning to 0, specifically:
the left side of the formula calculates the degree of identity of the elements of the two examples, and the right side calculatesThe elements in (1) can be inTo the extent that it matches, once the current element matches it ends, the matching of the next element begins.
Step S1063: and taking the filial generation set in the iterative reproduction as a parent set in the next reproduction to perform cross reproduction, individual recombination and individual variation again, and outputting the filial generation sets in the iterative reproduction and the corresponding similarity.
In the ecological reproduction test case algorithm, the more times the algorithm is reproduced, the larger the difference between the following cases and the relational cases, so that the reproduction times of the first three times can be changed if a large number of cases are neededAnd (5) adjusting the height. After expected output is designed for later-generation cases, the test cases are automatically run through a unit test tool or an automatic test tool, and latent bugs which are not found in a program can be effectively found.
In addition, it should be emphasized that, in the preset ecological reproduction test case algorithm provided in the embodiment, cross reproduction is performed to exchange elements between cases, individual recombination is performed to exchange elements between cases, and individual variation appropriately modifies some elements. These three steps bring ecological proliferation diversity to the offspring collection. The offspring set has the excellent characteristics and new diversity of the inherited self-relationship case set, and can make up for short boards with insufficient number of relationship cases. And the offspring use case set is taken as an assistant, so that the offspring use case set has ideal assistant test performance and helps to find out latent Bug.
It should be noted that the random use case obtained by simply and directly generating the use case set by the random number in the conventional manner has no relation with the function requirement and the code to be tested. Although a large number of use cases are easily available, these use cases generally have low coverage rates, and it is necessary to achieve a level close to the exhaustive test to ensure good coverage rates. For a program with large input data quantity, the number scale of cases for exhaustive testing is extremely large, and the method is practically not feasible at all. The parent set in this embodiment is obtained by analyzing the functional requirements and the processing manner, and has the advantages of reasonability, diversity and the like, and the propagated and generated extended use case set is better than the randomly generated use case set.
In summary, according to the method for designing and generating test cases based on the relational analysis, through the analysis of the function and input complex program development relations, the relations can comprehensively cover the function requirements and the processing modes, so that the efficient, reasonable and complete test cases can be designed, the latent, difficult-to-find program bugs can be found out, and the capability of testers and programmers in designing the test cases can be improved. For a complex program with large input data amount, after a relation case set is designed, a large number of descendant case sets with relation characteristics and diversity can be obtained through multiple rounds of reproduction, recombination and variation by relying on the proposed ecological reproduction algorithm and taking the relation case set as the basis, and the complex program with large input data amount can be comprehensively and effectively tested in an auxiliary manner.
Referring to fig. 4, a schematic structural diagram of a test case design and generation system based on relationship analysis in a third embodiment of the present invention is shown, where the system includes:
the relation analysis module 10 is configured to obtain a function requirement and a processing mode of a program to be tested, and perform relation analysis on variables in the program to be tested according to the function requirement and the processing mode to obtain a relation between input variables and output variables;
further, the relationship analysis module 10 further includes:
the system comprises a whole input set analysis unit, a test unit and a test unit, wherein the whole input set analysis unit is used for acquiring a whole input set corresponding to the program to be tested and acquiring input variables and effective input conditions for expressing the whole input set according to the whole input set;
the first relation analysis unit is used for analyzing the value types of the single variables and various relations among the input variables by taking the input variables and the effective input conditions as analysis objects according to the functional requirements and the processing mode;
the second relation analysis unit is used for respectively inputting all input variables into the program to be tested to obtain output variables, and corresponding the output variables to the input variables according to the function requirements to obtain the relation between the output variables and the input variables;
the use case set generating module 20 is configured to design a plurality of relation use cases according to the relation between the input variables and the output variables to obtain a relation use case set;
the use case reproduction module 30 is configured to input the relational use case set to generate a subsequent use case set according to a preset ecological reproduction test use case algorithm.
Further, the use case propagation module 30 further includes:
a parameter setting unit for setting the value range of the elements in the use case asSelecting a similarity function;
an iteration reproduction unit for inputting the relation case setAnd initializing the parent setAnd for the parent setTo carry outPerforming iteration of the secondary loop to reproduce to obtain a progeny use case set;
further, the iterative multiplication unit further comprises:
a spawn execution subunit to spawn the parent setPerforming cross propagation to obtain a primary set, then performing individual recombination on the primary set to obtain a recombined set, and performing individual variation on the recombined set to obtain a variant set;
the similarity calculation operator unit is used for taking the obtained variation set as an offspring set in the iterative reproduction and calculating to obtain the similarity between the offspring set and a parent set in the reproduction;
a reproduction cycle subunit, configured to use the offspring set in the previous iterative reproduction as a parent set in the next reproduction, perform cross reproduction, individual recombination, and individual variation again, and output the offspring sets in the previous iterative reproduction and corresponding similarity;
further, the spawning execution subunit is further configured to:
collecting the parentEach parent use case inRandomly matching another parent use caseSo that two different father cases can exchange partial elements to obtain two sub cases;
acquiring a random number, and calculating according to the random number and a parameter corresponding to the current cross reproduction to obtain the number of elements exchanged in the current cross reproduction by the two relation cases;
and calculating the number of the interchange elements of the two relation cases in the current cross reproduction according to the following formula:
wherein m is 1 Representing the number of elements that the two relational use cases interchange in the current cross-breeding,andrespectively represent the lengths of two relational use cases,denotes the parameter of the d-th cross breeding, r denotes a random number and;
obtaining the parameters corresponding to the current cross breeding according to the following formula:
wherein,representing initial cross-breeding parameters, and a, b and c represent three constant parameters;
the system is also used for obtaining the length of each nascent case in the nascent set, and interchanging the positions of two elements of each nascent case according to the length and the random number to obtain a regrouping set;
the method is also used for carrying out variation on the elements in the recombination set according to a preset value range;
if the elements in the relation case set are numerical value types, calculating to obtain a current variation value according to the numerical value of the element to be varied in the recombination set and a control parameter of the current individual variation degree, and carrying out individual variation on the element to be varied according to the current variation value to obtain a variation-completed numerical value, wherein the variation-completed numerical value range is the same as a preset value range;
obtaining the current variance value according to the following formula:
wherein,which is indicative of the current value of the variance,the absolute value of the numerical value corresponding to the element to be varied is represented by | x | which is a control parameter of the variation degree of the current individual;
if the elements in the relation case set are of non-numerical type, the preset value range is selectedRandomly selecting one element to replace the element to be mutated to complete individual mutation;
further, the similarity operator unit is further configured to:
calculating the similarity between the child set and the parent set in the reproduction according to the following formula:
wherein,is shown asThe similarity between the parent set and the child set in the sub-iterative multiplication,is shown asThe parent set in the sub-iterative multiplication,is shown asThe set of children in the secondary iteration of multiplication,is shown asThe number of use cases in the child set in the sub-iterative multiplication,representing the first in a parent setIndividual caseAnd the warpThe propagated filial generation collective caseThe similarity of (2);
if the elements in the relation case set are numerical types, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent caseAnd its sub-case x,representing a parent caseTo middleThe number of the elements is one,the second of the presentation sub-case xThe number of the elements is one,the length of the use case is represented,a parameter representing the degree of initial variation;
if the elements in the relation case set are of non-numerical type, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent caseAnd its sub-case x,the weight parameter is represented by a weight value,representation for judging parent use caseTo middleAn elementAnd sub-case xEach elementWhether or not the same function is used,represents an elementMatch with all elements in the sub-case x ifIn presence of elements and use casesIf the two are the same, 1 is returned, otherwise 0 is returned.
In summary, according to the method for designing and generating test cases based on the relational analysis, through the analysis of the function and input complex program development relations, the relations can comprehensively cover the function requirements and the processing modes, so that the efficient, reasonable and complete test cases can be designed, the latent, difficult-to-find program bugs can be found out, and the capability of testers and programmers in designing the test cases can be improved. For a complex program with large input data amount, after a relation case set is designed, a large number of descendant case sets with relation characteristics and diversity can be obtained through multiple rounds of reproduction, recombination and variation by relying on the proposed ecological reproduction algorithm and taking the relation case set as the basis, and the complex program with large input data amount can be comprehensively and effectively tested in an auxiliary manner.
Another aspect of the present invention also proposes a storage medium on which one or more programs are stored, the programs, when executed by a processor, implementing the above-described method for people counting based on a multimodal network.
In another aspect, the present invention further provides a computer device, which includes a memory and a processor, wherein the memory is used for storing a computer program, and the processor is used for executing the computer program stored in the memory, so as to implement the above-mentioned people counting method based on the multi-modal network.
Those of skill in the art will understand that the logic and/or steps illustrated in the flowcharts or otherwise described herein, such as an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Further, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, various steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The above examples are merely illustrative of several embodiments of the present invention, and the description thereof is more specific and detailed, but not to be construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.
Claims (9)
1. A test case design and generation method based on relational analysis is characterized by comprising the following steps:
acquiring function requirements and a processing mode of a program to be tested, and performing relation analysis on variables in the program to be tested according to the function requirements and the processing mode to obtain a relation between input variables and a relation between the input variables and output variables;
designing a plurality of relation use cases according to the relation between the input variables and the output variables to obtain a relation use case set;
inputting a relation case set to generate a descendant case set according to a preset ecological reproduction test case algorithm, wherein the method specifically comprises the following steps:
2. The method for designing and generating test cases based on relational analysis according to claim 1, wherein the step of obtaining the functional requirements and the processing modes of the program to be tested, and performing relational analysis on the variables in the program to be tested according to the functional requirements and the processing modes to obtain the relationships between the input variables and the output variables comprises:
acquiring a whole input set corresponding to the program to be tested, and acquiring input variables and effective input conditions for expressing the whole input set according to the whole input set;
analyzing the value types of the single variables and various relations among the input variables by taking the input variables and the effective input conditions as analysis objects according to the functional requirements and the processing mode;
and inputting all input variables into the program to be tested respectively to obtain output variables, and corresponding the output variables to the input variables according to the function requirements to obtain the relation between the output variables and the input variables.
3. The method according to claim 2, wherein the input of the relational case set isAnd initializing a parent set>And collecting/collecting the parent>Make and/or>The step of repeating the loop for the second time to reproduce the offspring case set comprises the following steps:
for the parent setPerforming cross propagation to obtain a primary set, then performing individual recombination on the primary set to obtain a recombined set, and performing individual variation on the recombined set to obtain a variant set;
taking the obtained variation set as a child set in the iterative reproduction, and calculating to obtain the similarity between the child set and a parent set in the iterative reproduction;
and taking the filial generation set in the iterative reproduction as a parent set in the next reproduction to perform cross reproduction, individual recombination and individual variation again, and outputting the filial generation sets in the iterative reproduction and the corresponding similarity.
4. The method according to claim 3, wherein the parent set is a set of test casesThe step of performing cross breeding to obtain a primary set comprises the following steps:
collecting the parentIs greater than or equal to>Randomly matching another parent use case>So that two different parent cases can exchange partial elements to obtain two sub cases;
the parent setIn each parent use case &>Randomly matching another parent use case>So that two different parent cases can exchange partial elements, and the step of obtaining two sub-cases comprises: />
Acquiring a random number, and calculating according to the random number and a parameter corresponding to the current cross reproduction to obtain the number of elements exchanged in the current cross reproduction by the two relation cases;
and calculating the number of the interchange elements of the two relation cases in the current cross reproduction according to the following formula:
wherein,represents the number of elements exchanged by the two relational use cases in the current cross breeding, and>and &>Respectively represents the length of two relation examples>Indicates the fifth->A parameter of minor cross breeding>Represents a random number and->;
Obtaining parameters corresponding to the current cross breeding according to the following formula:
wherein,representing initial cross-breeding parameters, and a, b and c represent three constant parameters;
the step of performing individual recombination on the primary set to obtain a recombined set comprises the following steps:
acquiring the length of each nascent case in the nascent set, and interchanging the positions of two elements of each nascent case according to the length and a random number to obtain a recombined set;
the step of performing individual variation on the recombination set to obtain a variation set comprises:
and carrying out variation on the elements in the recombination set according to a preset value range.
5. The method for designing and generating test cases based on relational analysis according to claim 4, wherein the step of mutating the elements in the reorganization set according to a preset value range comprises:
if the elements in the relation case set are numerical value types, calculating to obtain a current variation value according to the numerical value of the element to be varied in the recombination set and a control parameter of the current individual variation degree, and carrying out individual variation on the element to be varied according to the current variation value to obtain a variation-completed numerical value, wherein the variation-completed numerical value range is the same as a preset value range;
6. The method for designing and generating test cases based on relational analysis according to claim 5, wherein if the elements in the relational case set are numerical types, a current variation value is calculated according to the numerical values of the elements to be varied in the recombination set and the control parameters of the current individual variation degree, so as to perform individual variation on the elements to be varied according to the current variation value, thereby obtaining a variation-completed numerical value, and the step of completing the variation with the preset numerical range includes:
obtaining the current variance value according to the following formula:
7. The method according to claim 3, wherein the step of calculating the similarity between the child set and the parent set in the current iteration breeding by using the obtained variant set as the child set in the current iteration breeding comprises:
calculating the similarity between the parent set and the child set in the reproduction according to the following formula:
wherein,indicates the fifth->The similarity between the parent set and the child set in the sub-iterative multiplication, device for combining or screening>Indicates the fifth->The parent set in the sub-iterative multiplication, and/or>Indicates the fifth->The set of children in the sub-iterative multiplication->Represents a fifth or fifth party>Number of use cases in the child set in the sub-iteration multiplication, < > >>Indicates the fifth or fifth in the parent set>Case for each case>And longitude>The resulting offspring collection cases>The similarity of (c).
8. The method for designing and generating test cases based on relational analysis according to claim 7, wherein the method further comprises:
if the elements in the relation case set are numerical types, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent case>And its sub-case x, based on the numerical similarity->Representing a parent case>Middle and fifth>Element(s) is/are present>Indicates the ^ th of sub-case x>Element(s) is/are present>Indicates the length of the use case, and->A parameter representing the degree of initial variation;
if the elements in the relation case set are of non-numerical type, calculating the similarity between the two cases according to the following formula:
wherein,representing a parent case>And its sub-case x, a non-numeric similarity->A weight parameter is represented that is a function of,representing a decision for parent use case>In a fifth or fifth sun>Multiple elements>And { (v) } of sub-case x>Element/element->Whether or not the same function is used,indicates that the element is to be->Match all elements in the sub-case x if @>Presence of an element and case->If the two are the same, 1 is returned, otherwise 0 is returned.
9. A test case design and generation system based on relational analysis is characterized by comprising:
the system comprises a relation analysis module, a processing module and a processing module, wherein the relation analysis module is used for acquiring the function requirement and the processing mode of a program to be tested, and carrying out relation analysis on variables in the program to be tested according to the function requirement and the processing mode to obtain the relation between input variables and the relation between the input variables and the output variables;
the case set generating module is used for designing various relation cases according to the relation between the input variables and the output variables to obtain a relation case set;
the case reproduction module is used for inputting the relational case collection so as to generate a descendant case collection according to a preset ecological reproduction test case algorithm, and specifically comprises the following steps:
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211631619.3A CN115617700B (en) | 2022-12-19 | 2022-12-19 | Test case design and generation method and system based on relational analysis |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211631619.3A CN115617700B (en) | 2022-12-19 | 2022-12-19 | Test case design and generation method and system based on relational analysis |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115617700A CN115617700A (en) | 2023-01-17 |
CN115617700B true CN115617700B (en) | 2023-04-07 |
Family
ID=84880329
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211631619.3A Active CN115617700B (en) | 2022-12-19 | 2022-12-19 | Test case design and generation method and system based on relational analysis |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115617700B (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6625760B1 (en) * | 1999-08-03 | 2003-09-23 | Hewlett-Packard Development Company, L.P. | Apparatus and method for generating random tests for program validation using genetic evolution |
CN114595152A (en) * | 2022-03-08 | 2022-06-07 | 南京航空航天大学 | NuXMV-oriented safety key system state transition diagram test case generation method |
CN115248781A (en) * | 2022-09-22 | 2022-10-28 | 西南科技大学 | Combined test case generation method, device and equipment and readable storage medium |
Family Cites Families (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101859274B (en) * | 2009-04-07 | 2013-06-05 | 西门子(中国)有限公司 | Method and system for fuzz testing |
JP2012103791A (en) * | 2010-11-08 | 2012-05-31 | Mitsubishi Electric Corp | Program testing device, program testing method and program testing program |
CN102323906B (en) * | 2011-09-08 | 2014-01-08 | 哈尔滨工程大学 | MC/DC test data automatic generation method based on genetic algorithm |
KR101334806B1 (en) * | 2013-04-04 | 2013-11-29 | 비티에스테크놀로지스(주) | Method of proudcing input sets of test case in test case generating system |
CN108763055B (en) * | 2018-04-19 | 2020-08-25 | 北京航空航天大学 | Construction method of test case constraint control technology based on epigenetic inheritance |
CN111611152B (en) * | 2019-02-25 | 2023-08-04 | 北京嘀嘀无限科技发展有限公司 | Test case generation method and device, electronic equipment and readable storage medium |
CN113297059B (en) * | 2020-05-10 | 2024-08-30 | 浙江天猫技术有限公司 | Test case generation method, test method and device of tested software |
CN112699053B (en) * | 2020-08-03 | 2022-02-22 | 徐州工程学院 | Software testing method integrated with fuzzy clustering |
CN112052166B (en) * | 2020-08-26 | 2021-05-18 | 河海大学 | Test case generation method and device based on domination relationship |
CN114492259A (en) * | 2022-01-25 | 2022-05-13 | 杭州云合智网技术有限公司 | Random constraint method for interdependent member variables |
-
2022
- 2022-12-19 CN CN202211631619.3A patent/CN115617700B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6625760B1 (en) * | 1999-08-03 | 2003-09-23 | Hewlett-Packard Development Company, L.P. | Apparatus and method for generating random tests for program validation using genetic evolution |
CN114595152A (en) * | 2022-03-08 | 2022-06-07 | 南京航空航天大学 | NuXMV-oriented safety key system state transition diagram test case generation method |
CN115248781A (en) * | 2022-09-22 | 2022-10-28 | 西南科技大学 | Combined test case generation method, device and equipment and readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN115617700A (en) | 2023-01-17 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Boas | Machine models and simulations | |
Thomas | On the synthesis of strategies in infinite games | |
Skinner et al. | A method for using player tracking data in basketball to learn player skills and predict team performance | |
CN113687821A (en) | Intelligent code splicing method based on graphic visualization | |
Gamba et al. | Efficiently explaining CSPs with unsatisfiable subset optimization | |
CN115617700B (en) | Test case design and generation method and system based on relational analysis | |
Abdallah et al. | Exhaustive analysis of dynamical properties of biological regulatory networks with answer set programming | |
Ismail et al. | Game Theory Using Genetic Algorithms. | |
US7360184B1 (en) | Method and apparatus for scenario search based random generation of functional test suites | |
Zingaro | Algorithmic thinking: a problem-based introduction | |
CN118502924B (en) | Task generation method and system | |
Lagerkvist | State Representation and Polyomino Placement for the Game Patchwork | |
CN113268574B (en) | Graph volume network knowledge base question-answering method and system based on dependency structure | |
Chu | Semantics-based selection and code bloat reduction techniques for genetic programming | |
Sedano et al. | Towards generating essence kernels using genetic algorithms | |
Frier | Genetic Algorithms as a Viable Method of Obtaining Branch Coverage | |
CN114254260B (en) | Method, device, equipment and storage medium for mining unbalanced data group in game | |
CN109966744A (en) | A kind of dynamic is formed a team matched method and system | |
KR102355806B1 (en) | Machine Learning Inverse Prediction Method Using Genetic Algorithm | |
Juranko | Implementace současného použití několika náhradních modelů pro evoluční optimalizaci | |
Mai et al. | A Comprehensive Review of Association Rule Mining Based on Evolutionary | |
Dessanti et al. | Ultra-High Dimensional Optimization and Interactive Requirements Negotiation for New Acquisition Programs. | |
de Mendonça et al. | A framework for genetic algorithms in games | |
Chagas et al. | Assessing Multi-Objective Search Engines for GE: A Case Study in CNN Generation | |
Moroz | Software tool for solving inductive modelling tasks based on self-organizing combinatorial-genetic method |
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 |