CN103729297A - Test case generation method based on hierarchic genetic algorithm - Google Patents

Test case generation method based on hierarchic genetic algorithm Download PDF

Info

Publication number
CN103729297A
CN103729297A CN201310751237.9A CN201310751237A CN103729297A CN 103729297 A CN103729297 A CN 103729297A CN 201310751237 A CN201310751237 A CN 201310751237A CN 103729297 A CN103729297 A CN 103729297A
Authority
CN
China
Prior art keywords
path
source code
test case
predicate
hierarchical
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.)
Pending
Application number
CN201310751237.9A
Other languages
Chinese (zh)
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.)
Beijing Institute of Technology BIT
Original Assignee
Beijing Institute of Technology BIT
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 Beijing Institute of Technology BIT filed Critical Beijing Institute of Technology BIT
Priority to CN201310751237.9A priority Critical patent/CN103729297A/en
Publication of CN103729297A publication Critical patent/CN103729297A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a test case generation method based on a hierarchic genetic algorithm. The method can be used for effectively preventing and controlling inbreeding, so that the problems of premature convergence and local convergence are effectively solved. The method includes the steps that a program source code is inputted into a path analyzer, and the path analyzer carries out path analysis on the inputted program source code, then obtains a corresponding path list and outputs the path list to a test data generator; a predicate instrumenter carries out predicate instrumentation on the inputted source code and outputs the instrumented code to the test data generator; the test data generator firstly carries out hierarchy on an initial population through the hierarchic genetic algorithm, compares passing paths of individuals in hierarchies with objective paths of the individuals in the hierarchies through the utilization of the instrumented source code to obtain the matching values between the passing paths and the objective paths, and finally the test data generator gives test cases to the paths.

Description

A kind of method for generating test case based on hierarchical genetic algorithms
Technical field
The present invention relates to a kind of method for generating test case based on hierarchical genetic algorithms, belong to software testing technology field.
Background technology
Along with the develop rapidly of computer technology science, as the soul of computing machine, software plays a part very important, and the inefficacy of software may cause even threat to life safety of huge economic loss.People are more and more deep to the understanding of software test importance, and software test stage shared proportion in whole software development cycle increases day by day.Whether existing software testing technology, from needing the angle that is performed tested software to be conventionally divided into static test and dynamic test.Static test is not executive routine code and the mistake that may exist in finder code or the process of appraisal procedure code.Dynamic test is come the dynamic behaviour of check program and operation result to find mistake by working procedure in sample testing data.Dynamic test comprises three part core contents: the operation result of generating test use case, working procedure and proving program.
In test data robotization generation field, comparatively commonly symbol is carried out method, stipulations produce random number method, Korel method etc. according to demand at present.Symbol execution method is static test data generating method, for dynamic object-oriented program, is not suitable for using; By requirements specification, produce random number method and belong to dynamic approach, when adopting test case sample testing, this method is very effective to producing test data, but in the higher method of testing of constraint requirements, such as branch covers or path covering, its efficiency is very low, is difficult to produce satisfactory disaggregation; The Korel dynamic test data method of formation covering in path-oriented owned by France, the information of its branch function during according to program dynamic operation, constantly adjusts the value to the influential input variable of current branch function, and branch function is minimized.But shortcoming is if primary data is selected badly, is easily absorbed in the locally optimal solution in carry out desired path surely that differs.
The existing automatic example generation method based on genetic algorithm, mainly to carry out different improvement for corresponding fitness function and coding method, for example to the improvement of fitness function, can make the evolution in genetic algorithm more accurate, be exactly fitness function because eliminate individual main standard.Appropriate coding method simultaneously also can make follow-up search procedure more quick.Although these improve in test case generates, there is raising in various degree, but still some problems of ubiquity are the problem of " precocity " and local convergence.
Summary of the invention
The present invention is a kind of method for generating test case based on hierarchical genetic algorithms, energy effectively preventing " inbreeding " phenomenon, thereby effectively solved the problem of " precocity " and local convergence, increased the diversity of species simultaneously, be convenient to produce the test case that coverage is higher.
Realize technical scheme of the present invention as follows:
Based on a method for generating test case for hierarchical genetic algorithms, comprise the following steps:
Step 1: give path analysis device part loading routine source code, then path analysis device carries out path analysis to the program source code of input, obtains corresponding path list after analyzing, and path list is exported to test data generating;
Step 2: predicate instrumenter part is carried out predicate plug-in mounting to the source code of input, first instrumenter detects the source code of input, once detect that branch statement and loop statement just insert corresponding predicate after branch statement and loop statement, until predicate instrumenter detects all branches predicate and circulation predicate place, all plug-in mounting is complete, and the code after plug-in mounting is exported to test data generating;
Step 3: the fitness function that mainly utilizes hierarchical genetic algorithms and Huffman encoding in test data generating, first hierarchical genetic algorithms carries out layering to initial population, in layer, make a variation with interlayer, intersect, select genetic manipulation, the fitness function of Huffman encoding builds and utilizes the source code that plug-in mounting is good to compare with destination path by path individual in layer, obtain by the matching value of path and destination path, this matching value is posted the fitness value into this heredity individuality, then according to the rule of elimination of setting, compile, intersect, select genetic manipulation, last test Data Generator provides the test case for every paths.
The step that hierarchical genetic algorithms hierarchical block described in step 3 is concrete is as follows:
A. first produce random initial population GA;
B. initial population is carried out to layering and be respectively GA111, GA112, GA121, GA122, GA211, GA212, GA221, GA222;
C. set genetic algebra counting variable t=0, Group Hierarchical counter m=3;
D. first calculate the individual fitness GA(t in t generation the 3rd layer of GA population), judge whether to satisfy condition, meet just output as test case; Do not meet and enter step e;
E. between the sub-population of the 3rd layer, select, variation, interlace operation, and then calculate fitness function value, see and whether satisfy condition, if meet, export as test case, otherwise m-1, in the second layer, select again, variation, interlace operation;
If f. still do not satisfy condition at m=1 layer fitness function, counter adds 1 and enters into the second generation, and then repeating step d, till so circulation obtains the test case in coverage goal path always.
In the fitness function module of the Huffman encoding described in step 3, remember that t is x for the individuality of Advanced group species, x is the input data of tested program, and the path string that x passes through is designated as f (x), and the length of f (x) is designated as | f (x) |, total n bar path to be measured, f jrepresent j article of path to be measured, wherein j=1,2 ..., n, by calculating f (x) and f jmatching degree obtain the fitness function P (x) of x, specific formula for calculation is as follows:
P j(x)=(C j(f(x)))+1)*P j′(x);
P j ′ ( x ) = Σ k = 1 min ( | f ( x ) , | f j | ) m jk * d jk ( f ( x ) ) ;
Wherein: d jk: reflection f (x) and f jk position whether identical, if identical value is 1, otherwise be 0;
C j(f (x)): since first consecutive identical figure place;
M jk: f (x) and f during to k position jthe number of identical bits;
By calculating P j(x) we just can obtain f jmatching degree with f (x).
Compared with existing best technique, the invention has the advantages that:
1. the present invention has realized the automatic generation of test case, and the program that is suitably for source code rank generates corresponding test case, and utilizes hierarchical genetic algorithms to have speed and restrain preferably.
2. the framework of general frame of the present invention is simple, and stability is high, and execution efficiency is high;
3. the present invention has realized the model of a test case Auto-Generation Tool.
Accompanying drawing explanation
Fig. 1 is the process flow diagram of a kind of dirty data travel path discover method based on complex network of the present invention;
Fig. 2 is that the present invention collects, the procedure chart of simplification and visual track path;
Fig. 3 is the function call result schematic diagram of application program in the embodiment of the present invention;
Fig. 4 is Huffman coding schematic diagram of the present invention.
Embodiment
Below in conjunction with accompanying drawing, further the present invention is described in detail.
In dirty data travel path discover method based on complex network of the present invention, mainly comprise path analysis device, predicate instrumenter, three parts of test data generating.First the code of the source program of path analysis device to input is analyzed, thereby obtains the routing table of source code program.Predicate instrumenter carries out predicate plug-in mounting to the source code of input simultaneously, code after plug-in mounting and path list are exported to test data automatic generator simultaneously, in test data generating, mainly utilize the fitness function of hierarchical genetic algorithms and Huffman encoding, first hierarchical genetic algorithms carries out layering to initial population, makes a variation, intersects, the genetic manipulation such as selection in layer with interlayer.And the structure of the fitness function of Huffman encoding is to utilize plug-in mounting good source code carries out.Individuality in layer has been passed through to path compares with destination path, thereby obtain by the matching value of path and destination path, this matching value is posted the fitness value into this heredity individuality, then according to the rule of elimination of setting compile, intersect, the genetic manipulation such as selection, last test Data Generator provides the test case for every paths.
Below in conjunction with Fig. 1, describe workflow of the present invention in detail:
Step 1: give path analysis device part input source code, then path analysis device carries out path analysis to the program source code of input, obtains corresponding path list after analyzing, and path list is exported to test data generating.
Step 2: predicate instrumenter part is carried out predicate plug-in mounting to the source code of input, plug-in mounting is mainly to carry out at the branch function of program and cyclical function place, first instrumenter detects the source code of input, once detect branch statement and loop statement just branch statement and loop statement below insert corresponding predicate, until predicate instrumenter detects all branches predicate and circulation predicate place, all plug-in mounting is complete.Code after plug-in mounting is exported to test data generating and is used.
Step 3: test data generating part mainly comprises the fitness function design of hierarchical genetic algorithms layering and Huffman encoding.Wherein the layering of hierarchical genetic algorithms we take points three layers as example, each individuality divides two to carry out as shown in Figure 2 in every layer.Ground floor in Fig. 2 has 2 sub-populations, and every sub-population has again 2 sub-populations at the 2nd layer, and the second layer has 2 × 2 sub-populations,, every sub-population of the 2nd layer has again 2 sub-populations at the 3rd layer, and such the 3rd layer has 2 × 2 × 2 sub-populations.By that analogy, if ground floor has K1 sub-population, the sub-population in n-1 layer has Kn sub-population at n layer, the total sub-population of n layer.
Wherein as shown in Figure 3, its concrete step is as follows for the overall flow of the hierarchical genetic algorithms in test data generating:
A. first produce random initial population GA.
B. initial population is carried out to layering and be respectively GA111, GA112, GA121, GA122, GA211, GA212, GA221, GA222.
C. set genetic algebra counting variable t=0, Group Hierarchical counting technology device m=3, to divide three layers as example;
D. first calculate the individual fitness GA(t in t generation the 3rd layer of GA population), judge whether to satisfy condition, meet just output as test case.
If e. step 4 do not meet between the sub-population of the 3rd layer, select, variation, interlace operation, and then calculate fitness function value, and see and whether satisfy condition, if meet, export as test case, otherwise m-1 selects, variation, interlace operation in the second layer again.
If f. still do not satisfy condition at m=1 layer fitness function, algebraically counter adds 1 and enters into the second generation, and then repeating step 4, till so circulation obtains the test case in coverage goal path always.
The fitness function of the Huffman path code adopting designs as shown in Figure 4, Huffman encoding is mainly to be encoded in path, thereby the binary code string list that has obtained every paths by path being carried out to binary coding shows so that we carry out the structure of fitness function.
In the fitness function module of described Huffman encoding, remember that t is x for the individuality of Advanced group species, x is the input data of tested program, and the path string that x passes through is designated as f (x), and the length of f (x) is designated as | f (x) |, total n bar path to be measured, f jrepresent j article of path to be measured, wherein j=1,2 ..., n, by calculating f (x) and f jmatching degree obtain the fitness function P (x) of x, specific formula for calculation is as follows:
P j(x)=(C j(f(x)))+1)*P j′(x);
P j ′ ( x ) = Σ k = 1 min ( | f ( x ) , | f j | ) m jk * d jk ( f ( x ) ) ;
Wherein: d jk: reflection f (x) and f jk position whether identical, if identical value is 1, otherwise be 0;
C j(f (x)): since first consecutive identical figure place;
M jk: f (x) and f during to k position jthe number of identical bits;
By calculating P j(x) we just can obtain f jmatching degree with f (x).
Although combine accompanying drawing, the specific embodiment of the present invention has been described; but to those skilled in the art; under the premise without departing from the principles of the invention, can also make some distortion, replacement and improvement, these also should be considered as belonging to protection scope of the present invention.

Claims (3)

1. the method for generating test case based on hierarchical genetic algorithms, is characterized in that, comprises the following steps:
Step 1: give path analysis device part loading routine source code, then path analysis device carries out path analysis to the program source code of input, obtains corresponding path list after analyzing, and path list is exported to test data generating;
Step 2: predicate instrumenter part is carried out predicate plug-in mounting to the source code of input, first instrumenter detects the source code of input, once detect that branch statement and loop statement just insert corresponding predicate after branch statement and loop statement, until predicate instrumenter detects all branches predicate and circulation predicate place, all plug-in mounting is complete, and the code after plug-in mounting is exported to test data generating;
Step 3: the fitness function that mainly utilizes hierarchical genetic algorithms and Huffman encoding in test data generating, first hierarchical genetic algorithms carries out layering to initial population, in layer, make a variation with interlayer, intersect, select genetic manipulation, the fitness function of Huffman encoding builds and utilizes the source code that plug-in mounting is good to compare with destination path by path individual in layer, obtain by the matching value of path and destination path, this matching value is posted the fitness value into this heredity individuality, then according to the rule of elimination of setting, compile, intersect, select genetic manipulation, last test Data Generator provides the test case for every paths.
2. a kind of method for generating test case based on hierarchical genetic algorithms as claimed in claim 1, is characterized in that, the step that the hierarchical genetic algorithms hierarchical block described in step 3 is concrete is as follows:
A. first produce random initial population GA;
B. initial population is carried out to layering and be respectively GA111, GA112, GA121, GA122, GA211, GA212, GA221, GA222;
C. set genetic algebra counting variable t=0, Group Hierarchical counter m=3;
D. first calculate the individual fitness GA(t in t generation the 3rd layer of GA population), judge whether to satisfy condition, meet just output as test case; Do not meet and enter step e;
E. between the sub-population of the 3rd layer, select, variation, interlace operation, and then calculate fitness function value, see and whether satisfy condition, if meet, export as test case, otherwise m-1, in the second layer, select again, variation, interlace operation;
If f. still do not satisfy condition at m=1 layer fitness function, counter adds 1 and enters into the second generation, and then repeating step d, till so circulation obtains the test case in coverage goal path always.
3. a kind of method for generating test case based on hierarchical genetic algorithms as claimed in claim 1 or 2, it is characterized in that, in the fitness function module of the Huffman encoding described in step 3, remember that t is x for the individuality of Advanced group species, x is the input data of tested program, the path string that x passes through is designated as f (x), the length of f (x) is designated as | f (x) | and, total n bar path to be measured, f jrepresent j article of path to be measured, wherein j=1,2 ..., n, by calculating f (x) and f jmatching degree obtain the fitness function P (x) of x, specific formula for calculation is as follows:
P j(x)=(C j(f(x)))+1)*P j′(x);
P j ′ ( x ) = Σ k = 1 min ( | f ( x ) , | f j | ) m jk * d jk ( f ( x ) ) ;
Wherein: d jk: reflection f (x) and f jk position whether identical, if identical value is 1, otherwise be 0;
C j(f (x)): since first consecutive identical figure place;
M jk: f (x) and f during to k position jthe number of identical bits;
By calculating P j(x) we just can obtain f jmatching degree with f (x).
CN201310751237.9A 2013-12-31 2013-12-31 Test case generation method based on hierarchic genetic algorithm Pending CN103729297A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310751237.9A CN103729297A (en) 2013-12-31 2013-12-31 Test case generation method based on hierarchic genetic algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310751237.9A CN103729297A (en) 2013-12-31 2013-12-31 Test case generation method based on hierarchic genetic algorithm

Publications (1)

Publication Number Publication Date
CN103729297A true CN103729297A (en) 2014-04-16

Family

ID=50453378

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310751237.9A Pending CN103729297A (en) 2013-12-31 2013-12-31 Test case generation method based on hierarchic genetic algorithm

Country Status (1)

Country Link
CN (1) CN103729297A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106202387A (en) * 2016-07-08 2016-12-07 陈光宇 A kind of data consistency concurrent maintenance method
CN110399286A (en) * 2018-04-24 2019-11-01 西安邮电大学 A kind of automatic generation of test data based on independent pathway
CN112346997A (en) * 2020-12-04 2021-02-09 福州理工学院 Automatic test case generation method and terminal
CN114780439A (en) * 2022-06-13 2022-07-22 江西财经大学 Reuse method of test cases among similar programs facing to parameter path flow graph

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102323906A (en) * 2011-09-08 2012-01-18 哈尔滨工程大学 MC/DC test data automatic generation method based on genetic algorithm
CN102331966A (en) * 2011-01-10 2012-01-25 中国矿业大学 Software test data evolution generation system facing path
CN102855191A (en) * 2012-08-31 2013-01-02 中国人民解放军63928部队 Embedded basic software code branch coverage testing data inheritance searching method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102331966A (en) * 2011-01-10 2012-01-25 中国矿业大学 Software test data evolution generation system facing path
CN102323906A (en) * 2011-09-08 2012-01-18 哈尔滨工程大学 MC/DC test data automatic generation method based on genetic algorithm
CN102855191A (en) * 2012-08-31 2013-01-02 中国人民解放军63928部队 Embedded basic software code branch coverage testing data inheritance searching method

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
刘彦琴等: ""基于分层遗传算法的电力变压器优化设计"", 《西安交通大学学报》 *
巩敦卫等: ""一种新的多路径覆盖测试数据进化生成方法"", 《电子学报》 *
张毅坤等: ""一种改进的遗传算法在构件化软件测试用例优化中的应用研究"", 《2005 中国计算机大会》 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106202387A (en) * 2016-07-08 2016-12-07 陈光宇 A kind of data consistency concurrent maintenance method
CN106202387B (en) * 2016-07-08 2019-05-21 苏州超块链信息科技有限公司 A kind of data consistency concurrent maintenance method
CN110399286A (en) * 2018-04-24 2019-11-01 西安邮电大学 A kind of automatic generation of test data based on independent pathway
CN110399286B (en) * 2018-04-24 2023-05-12 西安邮电大学 Independent path-based automatic test data generation method
CN112346997A (en) * 2020-12-04 2021-02-09 福州理工学院 Automatic test case generation method and terminal
CN114780439A (en) * 2022-06-13 2022-07-22 江西财经大学 Reuse method of test cases among similar programs facing to parameter path flow graph
CN114780439B (en) * 2022-06-13 2022-09-27 江西财经大学 Reuse method of test cases among similar programs facing parameter path flow graph

Similar Documents

Publication Publication Date Title
Amoroso et al. Les Houches 2019: physics at TeV colliders: standard model working group report
CN103257921B (en) Improved random forest algorithm based system and method for software fault prediction
CN104346278A (en) Matrix-model-based software testing method
Levitin et al. Reliability of series-parallel systems with random failure propagation time
CN105022691B (en) A kind of increasingly automated method for testing software based on uml diagram
CN106452825B (en) A kind of adapted telecommunication net alarm correlation analysis method based on improvement decision tree
CN107391385B (en) A kind of construction method of Generation of software test case technology
CN105701596A (en) Method for lean distribution network emergency maintenance and management system based on big data technology
CN107871216A (en) A kind of recognition methods of power distribution network fragility node
CN102331966A (en) Software test data evolution generation system facing path
Han et al. AIMS-MUPSA software package for multi-unit PSA
CN103729297A (en) Test case generation method based on hierarchic genetic algorithm
CN102968375B (en) Based on the infeasible paths detection method of association rule mining
CN102831055A (en) Test case selection method based on weighting attribute
CN103902457A (en) Method for generating test data covering parallel program paths based on coevolution
CN107276072A (en) A kind of method of utilization steady state information qualitative assessment power system transient stability margin
CN105955927A (en) Constrained optimization algorithm based on decomposition-parallel genetic algorithm
CN104679945A (en) System comprehensive assessment method based on colored Petri network
CN107276093B (en) Power system probability load flow calculation method based on scene reduction
CN110674791B (en) Forced oscillation layered positioning method based on multi-stage transfer learning
Jiang et al. Test data generation approach for basis path coverage
Tsatsaronis The future of exergy-based methods
CN116613762A (en) Method and system for identifying key nodes in power grid area
CN106777712A (en) The method that chip checking random regression coverage rate is quickly improved based on linear learning
CN114781495A (en) Intelligent ammeter fault classification method based on sample global rebalancing

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140416