CN101436128B - Software test case automatic generating method and system - Google Patents

Software test case automatic generating method and system Download PDF

Info

Publication number
CN101436128B
CN101436128B CN2007101775341A CN200710177534A CN101436128B CN 101436128 B CN101436128 B CN 101436128B CN 2007101775341 A CN2007101775341 A CN 2007101775341A CN 200710177534 A CN200710177534 A CN 200710177534A CN 101436128 B CN101436128 B CN 101436128B
Authority
CN
China
Prior art keywords
variable
path
test case
software
measured
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.)
Expired - Fee Related
Application number
CN2007101775341A
Other languages
Chinese (zh)
Other versions
CN101436128A (en
Inventor
宫云战
杨朝红
陈俊亮
肖庆
张威
王雅文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing University of Posts and Telecommunications
Original Assignee
Beijing University of Posts and Telecommunications
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 University of Posts and Telecommunications filed Critical Beijing University of Posts and Telecommunications
Priority to CN2007101775341A priority Critical patent/CN101436128B/en
Publication of CN101436128A publication Critical patent/CN101436128A/en
Application granted granted Critical
Publication of CN101436128B publication Critical patent/CN101436128B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention provides a method for automatically generating software test cases. The method comprises the following steps of: A. reading to-be-tested software, carrying out lexical analysis, syntax analysis and semantic analysis on a source program of the to-be-tested software and generating an abstract syntax tree and a control flow graph of the to-be-tested software; B. preprocessing the source program of the to-be-tested software by traversing the generated abstract syntax tree, identifying initial input-output variables and compressing the space of a definition domain of the initial input variables; and C. generating a path of program elements of the current to-be-tested software by traversing the control flow graph, carrying out assignment operation, implication operation and backtracking operation on the variables in the path, and generating the test cases. The invention also provides a system for automatically generating software test cases. The method and the system for automatically generating the software test cases can accurately and automatically generate the test cases according to the given program elements of the to-be-tested software and verify the generated test cases, thereby improving the accuracy, efficiency and automation degree of the test cases.

Description

Software test case automatic generating method and system
Technical field
The present invention relates to software testing technology, relate in particular to a kind of software test case automatic generating method and system.
Background technology
Software testing technology develops in depth, and the method for testing software that new efficient is high continues to bring out, and statistics shows; In present stage; In all software test expenses, about 40% flower comprises generating test data and checkout result on test case; About 50% the flower write with compilation script on, about 10% spends in the execution and configuration management of test script.
In numerous method for testing software, coverage test is the most frequently used a kind of method of testing, so-called coverage test; Promptly, at first select the paths P of containing element E, then the test case C of generation pass P to given element E; If test case C does not exist; Then should select other path P ', if path P ' do not exist explains that element E can not carry out.Said process moves in circles, and wherein the test case of generation pass P is a key problem.The test case of path P generation at present mainly is to accomplish by manual work, needs great amount of time.Under many circumstances, if the path P more complicated, for example, the branching ratio that comprises is more, perhaps branch's more complicated, and it is artificial that to generate test case almost be unlikely.
The generation of test case is the basis of software test, and no matter which kind of method of testing all relates to this problem.A variety of method for generating test case are arranged at present, and like genetic algorithm, random approach, climbing method, exploratory method, the method for solving equation etc., but achievement in research is from practical very big distance in addition.This also is one of principal element that restricts at present the software testing technology development.In the advanced Software Testing Tool of being developed in the world at present, generally all avoid test case and generate this problem automatically, the mode of semi-automatic generation test case perhaps is provided to multipotency.
Be engaged in both at home and abroad in the enterprise of software test at present, mostly adopting manual type or computer-assisted way to generate use-case.These the two kinds shortcomings that generate the test case method are:
1) generate use-case and require a great deal of time, testing efficiency is low;
2) need the very software test personnel of specialty, and need these personnel very familiar tested software;
3) the test effect is with a low credibility.
Since the last century the nineties, the cost of software test and maintenance is increasingly high, will reach 30%~50% of software development total expenses basically in China; In the U.S., this numeral will reach more than 50%, have in addition up to more than 80%; In this ratio; Wherein quite a few is a labour cost, and in software test procedure, the artificial test case that generates has occupied very most of the time.
The automatic generation of test case is one of target of pursuing of software testing technology always; But this is a very complicated problems; Many in the world scientists have paid great effort for this reason; But its effect is not very good, with regard to present research level, also has sizable distance from actual can the use.But it successfully solves improving software quality, and the shortening software development time all has important theoretical meaning and use value.
Summary of the invention
Fundamental purpose of the present invention is to provide a kind of software test case automatic generating method, can generate satisfactory test case set to tested program according to given software under testing program element, has improved the efficient and the automaticity of software test.
Another object of the present invention is to provide a kind of software test case automatic creation system; Can realize according to given software under testing program element; Search generates satisfactory test case set to tested program, thereby has improved the efficient and the automaticity of software test.
For achieving the above object, technical scheme of the present invention is achieved in that
A kind of software test case automatic generating method, its this method may further comprise the steps:
A, read software under testing, software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generate the abstract syntax tree and control flow graph of software under testing;
The abstract syntax tree that B, traversal are generated carries out pre-service to software source program to be measured, and said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression;
C, traversal are controlled flow graph, generate the path of current software under testing program element, and the variable in institute's generation pass is carried out assignment operation, subsume and trace-back operation, generate test case.
In the technique scheme, said step C specifically comprises:
C1, the software under testing program element that provides according to the user generate the path of carrying out the present procedure element through traversal control flow graph;
The rank of variable and correlated variables in C2, the calculating institute generation pass, and initialization condition counter;
C3, the input variable of conditional statement in the said path of step C1 is enumerated assignment, and whether the value of judgment variable be empty, if be sky then execution in step C5, otherwise execution in step C4;
C4, carry out subsume and judge whether new contradiction occurring according to the value of input variable among the step C3, if find new contradiction, execution in step C5 then, otherwise execution in step C6;
C5, the value of input variable is recalled, judged whether also will recall according to the number of times of having recalled, if not, execution in step C1 then; If, then recall, and judge and to recall whether success according to the correlativity of variable, if success then return step C3, otherwise would return step C1;
The current count value of C6, condition counter increases certainly, and judges whether current count value equals or exceeds the conditional number on the path, if then obtain a test case, otherwise return step C3.
Wherein, step C1 further comprises:
C1.1, the software under testing program element that provides according to the user; Generate the path of carrying out the present procedure element through traversal control flow graph, and judge whether the path that generates is empty, if be empty; Then finish current flow process and point out the failure of user's generation pass, otherwise execution in step C1.2;
The condition of the expression formula in C1.2, the extraction path in the conditional statement, variable and the unique determined value of ability;
C1.3, the original input variable field of definition after step B compression in the path is carried out space compression once more;
C1.4, the unreachable path of calculating also judge whether current path can reach, if current path is unreachable, then returns step C1.1 and regenerate new route.
Above-mentioned steps B further comprises:
B1, in the software under testing program the extra code of plug-in mounting, with the information of acquisition program behavior when being performed.
In the technique scheme, said method further comprises:
D, the test case that step C is obtained are verified.
This step D comprises:
D1, the test case driving execution software under testing program that generates according to step C, and according to the path of the actual execution of the code record of plug-in mounting;
D2, the actual execution route of comparison and destination path judge whether actual execution route and destination path meet, if do not meet then execution in step C1; If meet, then return to the user with the test case storage that obtains and with it.
Said abstract syntax tree comprises object and the symbol table of representing type information.
The present invention provides a kind of software test case automatic creation system simultaneously, and this system comprises:
Analysis module reads software under testing, and software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generates abstract syntax tree and control flow graph;
Pre-processing module, the abstract syntax tree through the traversal analysis module generates carries out pre-service to software source program to be measured, and said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression;
The test case generation module travels through the control flow graph that is generated, and cyclic search generates test case.
In the technique scheme, said test case generation module further comprises:
The path generation unit, the software under testing program element according to the user provides generates the path of carrying out the present procedure element through traversal control flow graph;
Processing unit is used for calculating the rank of variable and correlated variables in the path that is generated and initialization condition counter;
Assignment is enumerated to the input variable in the conditional statement in institute's generation pass in the assignment unit, and whether the value of judgment variable is empty;
Contain the unit, carry out subsume according to the value of variable in the assignment unit, and judge whether to occur new contradiction;
Trace unit, is recalled the value of variable for empty or when new contradiction occurring in the value of variable;
Judging unit, the current count value of condition counter be from increasing, and declare current count value and whether equal or exceed the conditional number on the path.
Wherein, this system further comprises:
Authentication module, the test case driving execution tested program of utilizing the test case generation module to generate, and, verify whether actual execution route conforms to destination path according to the path of the actual execution of plug-in mounting code record.
Software test case automatic generating method of the present invention and system; Since adopted the compression variable the region of search, utilize branch's contradiction to calculate unreachable path, use subsume to find contradiction as soon as possible, preferentially calculate multiple heuristic strategies such as unique certification condition; So can obtain satisfactory test case set according to given software under testing program element search exactly; The present invention simultaneously also can verify the test case that generates; Improve the accuracy of test case, improved the efficient and the automaticity of software test greatly.
Description of drawings
Fig. 1 is the realization flow synoptic diagram of software test case automatic generating method of the present invention;
Fig. 2 carries out pretreated schematic flow sheet in the inventive method to software under testing;
Fig. 3 is the realization flow synoptic diagram that generates test case in the inventive method automatically.
Embodiment
Below in conjunction with specific embodiment and accompanying drawing the present invention is described further.
The invention provides a kind of software test case automatic generating method; Its basic thought is: at first; Read software under testing; Software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generate abstract syntax tree, control flow graph and determine judgement (DD, Decision to Decision) figure; Then, tested program is carried out pre-service, comprising: discern original input, output variable, and the field of definition of original input variable is carried out space compression, the automatic plug-in mounting of the line program of going forward side by side etc.; Then, through traveling through above-mentioned control flow graph, generate the execution route of software under testing program element, the variable of generation pass is carried out assignment operation, subsume and trace-back operation, generate test case; At last, the driving execution tested program compares the actual execution route and the destination path of the above-mentioned program element that provides, and whether inspection gained test case meets the path that requires.
Fig. 1 is the realization flow synoptic diagram of software test case automatic generating method of the present invention, and as shown in Figure 1, this method may further comprise the steps:
Step 1, read software under testing, software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generate the abstract syntax tree and control flow graph of software under testing.
Step 2, through the traversal abstract syntax tree, software source program to be measured is carried out pre-service, said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression.
Step 3, traversal are controlled flow graph, generate the path of current software under testing program element, and the variable in institute's generation pass is carried out assignment operation, subsume and trace-back operation, generate test case.
Step 4, the test case driving execution software under testing measuring program that utilizes step 3 to generate are verified the test case that obtains.
Wherein step 1 specifically comprises:
Step 1.1, read the software under testing source program, software source program to be measured is carried out lexical analysis;
Software under testing is carried out lexical analysis (Lexical analysis), and this lexical analysis is that follow-up formation syntax tree provides needed symbol node, like constant and name.
Step 1.2, on the basis of step 1.1, software source program to be measured is carried out grammatical analysis and semantic analysis, generate abstract syntax tree;
Software under testing is carried out grammatical analysis (Parsing), and said grammatical analysis provides the syntax tree that contains the intermediate node of representing corresponding syntactic structure, and this syntax tree comprises the leafy node of representing non-reserved word terminal symbol and the intermediate node of representing syntactic structure; Semantic analysis (Semantic analysis) is further handled name and action scope; Generate abstract syntax tree; This abstract syntax tree comprises object and the symbol table of representing type information, and they are connected into tree structure, and this is the most basic output of compiler front-end; Abstract syntax tree comprises all from the resulting relevant information of source code, and can embody the syntactic structure of source program fully.
Above-mentioned abstract syntax tree has consistent tactic pattern, is made up of dissimilar nodes, and each category node all is described as a class formation.All syntax tree nodes are all supported unified visitor's pattern interface, so just can carry out further multi-form processing, traversal visit and output to abstract syntax tree through visitor's pattern easily.
Step 1.3, on the basis of generation abstract syntax tree, generate control flow graph and DD figure;
This process is the process of a traversal abstract syntax tree.Usually, program control flow figure representation be (N, E, Entry, Exit).Wherein, N represents the set of node, statement in the reflection program and condition judgment; E represents the set of directed edge, the control flow relation in the reflection program between statement; Entry is the fixing unique entry node of program; Exit be program unique withdraw from node.Briefly: the control flow graph is exactly to have single, fixing entry node and export the digraph of node.On the basis of control flow graph, can analyze and form DD figure.
DD figure is a kind of control flow graph of having simplified: some node in the control flow graph only is in the same branch of program, and this node does not have special use when path analysis, reduces the analysis efficiency of control flow graph sometimes on the contrary, need to simplify.To control flow graph and further simplify, what obtain is this except the entrance and exit node, and the number of degrees of all the other nodes all are called DD figure greater than 2 control flow graph.
Step 2 specifically comprises:
Step 2.1, through the traversal abstract syntax tree, discern original input variable, and confirm its field of definition;
Original input variable generally includes global variable and the static variable of using in function parameter, the function, at first through the traversal abstract syntax tree, identifies these variablees.The field of definition of variable is confirmed according to type and operating system environment corresponding in the language of tested program usually.The form in variable-definition territory is:
{ (x1, D X1), (x2, D X2) ..., wherein x represents variable name, and D represents its field of definition.
Step 2.2, through the traversal abstract syntax tree, identification output variable and output statement;
Identify global variable, static variable, output statement, the return statement of program and quote shape parameter.
Step 2.3, the field of definition of original input variable is carried out space compression;
According to the field of definition of original input variable, assignment and conditional statement in the program, carry out space compression from top to bottom, the result of compression is: { (x1, D ' X1), (x2, D ' X2) ...;
The field of definition of original input variable is determined that by type of variables and operating system environment the assignment in the calculation procedure and the limited range of conditional statement further compress the value space of original input variable.
Step 2 further comprises:
Step 2.4, in the tested software program, insert extra code, with the information of acquisition program behavior when being performed;
Above-mentioned extra code can be a statement.Plug-in mounting is mainly confirmed the plug-in mounting point according to the control flow graph, in beginning, the bifurcation of tested program control flow graph tested program is implemented plug-in mounting, generates the plug-in mounting statement tree node on the abstract syntax tree then, abstract syntax tree is changed again being output as source program then.
For example, follow procedure:
if(x>0){
x=3;
}
else{
x=-3;
}
Through shape behind the automatic plug-in mounting as:
if(x>0){
Branch [1] ++; // automatic the statement that inserts
x=3;
}
else{
Branch [2] ++; // automatic the statement that inserts
x=-3;
}
In carrying out the process of tested program, routing information that just can the actual execution of collection procedure.
Control flow graph through traversal in the step 3; Use the compression variable the region of search, utilize branch's contradiction to calculate unreachable path, use subsume to find contradiction as soon as possible and preferentially calculate multiple inspiration Test Strategy such as unique determined value condition, cyclic search generates test case;
This step 3 specifically comprises:
Step 3.1, the software under testing program element E that provides according to the user; Generate the path P of carrying out present procedure element E through traversal control flow graph, and judge whether the path P that generates is empty, if be empty; Then finish current flow process and point out the failure of user's generation pass, otherwise execution in step 3.2;
Above-mentioned path P is not necessarily unique; The software under testing program element E that the user provides can be statement, conditioned disjunction path (if E be the path so P just can only be E; And unique) etc.; Software under testing program element E according to the user provides in advance schemes the paths P of generation executive routine element E automatically, P={B according to control flow graph and DD 1→ B 2→ ... → B L, this path is not necessarily unique, on path P, has also provided a set of circumstances { B from top to bottom 1→ B 2→ ... → B L;
If the path that generates comprises control flow graph node, then this path is not empty; If the path that generates does not comprise control stream node, then this path is empty.
The condition of the expression formula in step 3.2, the extraction path P in the conditional statement, variable and the unique determined value of ability;
Expression formula in the conditional statement and variables extraction are come out, and wherein, expression formula is used for the calculating of condition, and variable is as the operand of subsequent searches process.This process is to carry out along the path P that step 3.1 provides, and also will consider assignment statement on the path in the process.Some condition can be confirmed the value of certain or some variablees uniquely.And these implicit values are just the same as assignment, no longer need further search.This can reduce the search volume greatly.To preferentially calculate this condition;
For example, conditional statement: if (a==3) ..., at this moment, the value space of variable a just can only be { 3};
The search principle that the above-mentioned preferential strategy that calculates the condition of the unique determined value of ability is derived is the limited area first search: some variable is at initial or some constraint of process; The region of search is become have only limited several point, this variable of first search helps to find contradiction as early as possible or search for successfully under this condition.
For example, suppose that x is an integer variable, if (1≤x≤3) ..., this condition has been confirmed x ∈ [1,2,3].
Step 3.3, the original input variable field of definition space in the path P is compressed once more;
Original input variable field of definition space after step 2.3 compression in the path P is compressed once more; Because the condition of the unique determined value of ability that in step 3.2, finds; Can influence the region of search of some variable, so the region of search of variable will change at any time, with the search volume of minimizing variable;
According to path P and { (x1, D ' X1), (x2, D ' X2) ..., once more field of definition being carried out space compression, the result of compression is: (x1, D " X1), (x2, D " X2) ....
Step 3.4, the unreachable path of calculating also judge whether current path P can reach, if current path is unreachable, then returns step 3.1 and regenerate new route;
Unreachable path is meant that in given input interval this path is possibly be performed never.
According to the result of step 3.3, check whether the value space of each variable is empty, if the value space of certain variable is sky then means that current path P is unreachable path, then returns step 3.1;
Analysis shows, has a large amount of unreachable paths in the general program.In the process that produces test case; It is possible selecting unreachable path, and this also is one of principal element that influences testing efficiency, therefore should stop the calculating to this path as early as possible; Return step 3.1 regenerating new different paths, thereby get rid of those unreachable paths.
For example:
if(x>0){
x=3;
}
if(x<0){
x=4;
}
In above-mentioned example, software under testing program element E refers to and will cover statement x=3; Get the path that the branch of true value forms in fact be exactly a unreachable path for two if conditions in the program, because x>0 and x<0 is the condition of two contradictions.
The rank of variable and correlated variables among step 3.5, the calculating current path P;
The variable of a direct or indirect influence of variable is called correlated variables.According to the correlativity of variable, can set up the intersecting chain of variable.The immediate predecessor correlated variables of certain variable is meant first precursor variable of this variable in this intersecting chain, is mainly used in and recalls.The rank of variable, it is defined as: the level definition of input variable is 1; The level definition of output variable adds 1 for the maximum level of the variable in the expression formula of this variable in the middle of one.The rank of variable is valuable for recalling of variable.
Step 3.6, initialization condition counter;
A plurality of condition formation condition set { B that path P comprises 1→ B 2→ ... → B L, need a condition counter to write down condition when pre-treatment.When the condition of pre-treatment is designated as B i, the count value i=1 of initialization condition counter.
Whether step 3.7, the value that the input variable of conditional statement in the path P is enumerated assignment (rollback (Backtracing)) and judgment variable are empty, if be sky then execution in step 3.9;
Each assignment all will have record, be used to prevent that the value of composing from composing again, value for the empty value of variable in the value space that mean all by tax.The value space is that sky is two notions for empty and this time value, though the value space is not empty, all values were all got, and at this time can return null value;
At first extract B iIn still do not have definite value variable set.At condition B iFor really retraining down, from the variable set, select a variable, according to its value space; Select a value according to heuristic rule; And judge whether this value is empty, and each value all will guarantee to get the value that those were got, though might the value space not be empty therefore; But all fingers were all got, and at this time can return null value.
Step 3.8, carry out subsume and judge whether new contradiction occurring according to the value of variable in the step 3.7, if find new contradiction then execution in step 3.9, otherwise execution in step 3.10;
Contain (value contains, the codomain computing) and whether be that sky judges whether to occur new contradiction according to the value space of variable; Implication is meant that a variable is enumerated after the assignment in step 3.7, calculates the influence of this variable to other correlated variabless, adjusts the value spatial variations that other correlated variabless produce owing to current assignment; Subsume mainly is in order to find contradiction as soon as possible.In containing computation process; After one or one group of new variate-value are determined; This or this new value of group is implemented subsume can find contradiction as soon as possible; Concerning software, implication can be confirmed the value or the span of more heterogeneous pass variable, so simultaneously; Also can compress the scope of search volume, improve search efficiency.
Step 3.9, the value of variable is recalled, judged whether also will recall, if not according to the number of times of having recalled; Then return step 3.1; If then recall, and whether judgement recalls successful according to the correlativity of variable; If success then return step 3.7 otherwise is returned step 3.1;
Whether the value to variable is recalled, and gets back to step 3.1 and sees that having other value of not getting or not can get, in the given range of test macro setting, judge whether also will recall according to recalling (Backtracking) number of times;
According to step 3.5 nearby dependent backtrack to B k, recalling number of times and add 1, the current count value i of condition counter is changed to the condition k that dates back to.Whether can continue the definite value variable that still do not have of search in addition judges and to recall whether success according to the condition that dates back to; If the condition that dates back to can not continue to have searched for, be not sky though that is to say the variable-value space in the condition that dates back to, all values were all got, and at this time returned null value.
When producing contradiction, will implement to recall.Recall and help reducing unnecessary computing, algorithm is in the process of search, and the value of some variable may produce contradiction, in case and contradiction produces, just should stop to continue computing, reselect new assignment.
Single condition: at same condition B iIn, possibly exist two or morely when having identical or relevant variable, may produce contradiction, this contradiction just is confined at B iInner.Owing in variable assignments or the implication function that rollback (Backtracing) process takes place, can change the value or the span of some variable, therefore just might produce contradiction.Rollback is meant composes a new value to input variable, and guarantees that this value and the value of having composed do not repeat.
A plurality of conditions: at { B 1, B 2..., B mIn, when existing two or more branch condition to have identical or relevant variable, may produce contradiction.B for example i=if (a>4) ..., B j=if (a<=3) ..., just may produce contradiction.
Suppose { x I1, x I2..., x IkBe B iRelated variable set, { x M1, x M2..., x MpBe the set of the variable of determined value, { x J1, x J2..., x JLBe the variable set that this computing needs assignment, { x N1, x N2..., x NH}
Figure 2007101775341_0
{ x J1, x J2..., x JLBe the set of the variable that conflicts of this computing, { B I1, B I2..., B IjBe and { x N1, x N2..., x NHRelevant branch's set, then from B IjBeginning is recalled successively.In general, the variable that rank is low is preferentially recalled, and calculates fairly simple like this.
The current count value of step 3.10, condition counter is from increasing and judging whether current count value equals or exceeds the conditional number on the path P, if then obtain a test case, execution in step 4 then, otherwise return step 3.7;
Above-mentioned conditional number is by tested program decision itself, and the count value of counter is initialized as 1, and the current count value of condition counter is from increasing 1.
For example:
if(x>0){
x=3;
}
if(x>3){
x=4;
}
Above two if conditions get the path that true value forms and just comprise x>0 and x>3 two condition.If when the precondition count value is 2 then explanation handles has been the 2nd condition on this paths.
Step 4 further comprises:
Step 4.1, the test case driving execution software under testing measuring program that generates according to step 3.10, and according to the path of the actual execution of plug-in mounting code record;
Step 4.2, actual execution route and destination path judge whether actual execution route and destination path meet, if do not meet then return step 3.1; If meet, then return to the user with the test case storage that obtains and with it.
The plug-in mounting code record of front actual execution route; Itself and destination path are compared; If do not meet (promptly inequality); Explain that the test case that obtains can not cover software under testing program element E, will regenerate that this is because some the simplification approximate treatment in the test case generative process cause.
Following is two more typical examples, shows that program structure is complicated, the path is many, adopts general algorithm (genetic algorithm, random approach, climbing method, exploratory method, the method for solving equation) to need great amount of time.
Example 1: calendar converse routine calconv (source, year, month, date, days).This program is write by C++, comprises three modules, is respectively master routine, leap year determining program GetLeap and Transformation Computational Program calconv.
Example 2: draw fan-shaped program: draw fan-shaped by center, radius and starting point, terminal point angle.Functional form be Scir2 (row, col, a, b, t1, t2, color, xor).
Table 1 is program description, and is as shown in table 1.
Program name Number of lines The piece number The variable number Number of branches Path number The contradiction path number of branch's contradiction to calculating Contradiction path ratio
calconv 165 71 5 54 32408 31124 96%
Scir2 129 55 6 51 110598 91392 83%
Table 1
1) (branch's coverage test is exactly each branch that wants overlay program; The path covers wants every active path of overlay program (reachable path) exactly) branch's coverage test (the E here is exactly certain branch): generate test case at random, check of the influence of different regions of search testing efficiency.Table 2 is the coverage test result of branch,
As shown in table 2, can find out that the increase of region of search can produce very significant effects to testing efficiency.
Program Interval 100% branch covers the needed time
calconv Source:[1,10],Year:[1910,2049],month:[1,20],Date:[1,40],Days:[-50,50] 0.6s
calconv Source:[1,100],Year:[1800,2200],month:[1,100],Date:[1,100],Days:[-300,200] 4s
Scir2 Col:[1,500],a:[1,500],b:[1,500],t1:[-300,1000],t2:[-300,600],color:[0,225],xor:[0,9] 12s
Table 2
2) path testing of calconv.To every active path; Adopt the use-case technology (the E here is exactly certain path) that generates at random; First group of input span option table 1, " test duration 1 " that test result is as shown in table 2, table 3 is for adding the various inspiration Test Strategies (region of search of compression variable respectively; Utilize branch's contradiction to calculate unreachable path; Use subsume to find contradiction as soon as possible, preferentially calculate unique determined value condition) the test effect relatively, " path number 1 of being tested " in path number of being tested such as the table 3.
Limit the random code number Test duration 1 Test duration 2 The path number 1 of being tested Test duration 3 The path number 2 of being tested Test duration 4 The path number 3 of being tested
100 2s 1s 25 1s 83 1s 170
1000 12s 4s 89 5s 181 5s 220
10000 118s 45s 141 47s 223 46s 285
20000 235s 88s 182 92s 251 91s 303
?30000 350s 131s 191 136s 263 136s 303
?40000 464s 173s 193 182s 276 280s 304
?50000 580s 215s 193 227s 276 223s 305
?60000 696s 256s 201 273s 278 266s 311
?70000 812s 300s 207 319s 287 309s 315
?80000 927s 342s 209 364s 288 352s 321
?90000 1043s 384s 211 408s 288 397s 329
?100000 1158s 426s 212 446s 290 439s 329
Table 3
Test duration 2 is test durations of removing behind the unreachable path.Just on average, the test duration 2 is 37% of test durations 1, raises the efficiency 2.7 times.
Test duration 3 is test results of utilizing the search volume compress technique, removing unreachable path technique, can find out, the test duration 3 is more more a little than the test duration 2, mainly be to have increased some additional calculation, but the path number of being tested increases greatly.Just test same path number, utilization is should technology needed recalls number of times and should technology lack 1 one magnitude than not using at least.
Test duration 4 be utilize the search volume compress technique, remove unreachable path, condition reckoning technology, implications technology, the technological test result of unique definite condition.In fact, in this example, to the above-mentioned field of definition that provides, but the execution route number of this program has only 329.
3) path testing of Scri2.Table 4 is that the test result of various heuristic Test Strategies compares, and the implication of wherein each parameter is with table 3.
Because given example is fewer, so for recalling, the calconv average energy is saved 4s, the Scri2 average energy is saved 3s, and its effect is also not obvious, main cause be example very little.Consider general function,, generally also just arrive hundreds of row, so the purposes of recalling is not very big at tens of row according to the standard of soft project.
Limit the random code number Test duration 1 Test duration 2 The path number 1 of being tested Test duration 3 The path number 2 of being tested Test duration 4 The path number 3 of being tested
100 2203s 658s 871 298s 1345 308s 2488
1000 21635s 6216s 1885 2677s 2273 2756s 3642
2000 5126s 2691 5390s 3980
3000 7766s 2812 7965s 4196
4000 10004s 3232 10502s 4238
5000 12665s 3366 13070s 4443
6000 15011s 3411 15593s 4513
Table 4
Result from the above mentioned can know; Because software test case automatic generating method of the present invention and system have adopted multiple heuristic strategies; So can obtain satisfactory test case set according to given software under testing program element search exactly, improve the efficient and the automaticity of software test greatly.
In order to realize above-mentioned software test case automatic generating method, the present invention also provides a kind of software test case automatic creation system, and this system comprises: analysis module, pre-processing module, test case generation module and authentication module.
Wherein, analysis module reads software under testing, and software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generates abstract syntax tree, control flow graph.
Pre-processing module, the abstract syntax tree through the traversal analysis module generates carries out pre-service to software source program to be measured, and said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression.
The test case generation module travels through the control flow graph that is generated, and generates the path of current software under testing program element, and the variable in this path is carried out assignment operation, subsume and trace-back operation, and cyclic search generates test case.
Authentication module, the test case driving execution tested program of utilizing the test case generation module to generate, and, verify whether actual execution route conforms to destination path according to the path of the actual execution of plug-in mounting code record.
In the technique scheme; The test case driving execution software under testing program that authentication module utilizes the test case generation module to generate; And according to the path of the actual execution of plug-in mounting code record; If actual execution route and destination path meet, then return to the user, otherwise the test case generation module regenerates new test case with the test case storage that obtains and with it.
Wherein, the test case generation module further comprises:
The path generation unit, the program element to be tested according to the user provides generates the path of carrying out the present procedure element through traversal control flow graph;
Processing unit is used for calculating the rank of variable and correlated variables in institute's generation pass and initialization condition counter;
The assignment unit; Whether the value of the input variable in the conditional statement in institute's generation pass being enumerated assignment and judgment variable is empty; If be sky then send instructions, the value of variable recalled, otherwise sent instructions to the subsume of containing the unit value to trace unit;
Contain the unit, carry out subsume according to the value of variable in the assignment unit, and judge whether new contradiction to occur,, the value of variable is recalled, otherwise carried out judging unit if find new contradiction then send instructions to trace unit;
Trace unit is recalled the value of variable, judges whether also will recall according to the number of times of having recalled, if not, then send instructions to the path generation unit; If, then recall, and judge and to recall whether success according to the correlativity of variable, if success then send instructions to the assignment unit, otherwise send instructions to the path generation unit;
Judging unit; The current count value of condition counter is from increasing; And judge whether current count value equals or exceeds the conditional number on the path, if surpass then obtain a test case, otherwise assignment is enumerated to the input variable in the current conditional statement in the assignment unit.
Said control flow graph is except the entrance and exit node, and the number of degrees of all the other nodes are all greater than 2 control flow graph.
The above is merely preferred embodiment of the present invention, is not to be used to limit protection scope of the present invention.

Claims (8)

1. a software test case automatic generating method is characterized in that, this method may further comprise the steps:
A, read software under testing, software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generate the abstract syntax tree and control flow graph of software under testing;
The abstract syntax tree that B, traversal are generated; Software source program to be measured is carried out pre-service; Said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression, the field of definition of original input variable is by type of variables and the decision of operating system environment; According to the qualification effect of assignment in the calculation procedure and conditional statement, the value space of original input variable is further compressed;
C, traversal control flow graph, generation can cover the path of current statement to be measured or condition to be measured, and the variable in institute's generation pass is carried out assignment operation, subsume and trace-back operation, generates test case;
Said step C specifically comprises:
C1, the statement to be measured or the condition to be measured that provide according to the user generate the path of carrying out current statement to be measured or condition to be measured through traversal control flow graph;
The rank of variable and correlated variables in C2, the calculating institute generation pass, and initialization condition counter, the level definition of original input variable is 1, the level definition of other variable adds 1 for the maximum level of each variable in the definition expression formula of this variable;
C3, the original input variable of conditional statement in the said path of step C1 is enumerated assignment, and whether the value of judgment variable be empty, if be sky then execution in step C5, otherwise execution in step C4;
C4, carry out subsume and judge whether new contradiction occurring according to the value of original input variable among the step C3, if find new contradiction, execution in step C5 then, otherwise execution in step C6;
C5, the value of original input variable is recalled, judged whether also will recall according to the number of times of having recalled, if not, execution in step C1 then; If, then recall, and judge and to recall whether success according to the correlativity of variable, if success then return step C3, otherwise would return step C1;
The current count value of C6, condition counter increases certainly, and judges whether current count value equals or exceeds the conditional number on the path, if then obtain a test case, otherwise return step C3.
2. software test case automatic generating method according to claim 1 is characterized in that, said step C1 further comprises:
C1.1, the statement to be measured or the condition to be measured that provide according to the user; Generate the path of carrying out current statement to be measured or condition to be measured through traversal control flow graph; And judge whether the path that generates is empty; If be empty, then finish current flow process and point out the failure of user's generation pass, otherwise execution in step C1.2;
The condition of the expression formula in C1.2, the extraction path in the conditional statement, variable and the unique determined value of ability;
C1.3, the original input variable field of definition after step B compression in the path is carried out space compression once more; The field of definition of original input variable, is further compressed the value space of original input variable according to the qualification effect of assignment in the calculation procedure and conditional statement by type of variables and the decision of operating system environment;
C1.4, the unreachable path of calculating also judge whether current path can reach, if current path is unreachable, then returns step C1.1 and regenerate new route.
3. software test case automatic generating method according to claim 1 and 2 is characterized in that, said step B further comprises:
B1, in the software under testing program the extra code of plug-in mounting, with the information of acquisition program behavior when being performed.
4. software test case automatic generating method according to claim 3 is characterized in that, said method further comprises:
D, the test case that step C is obtained are verified.
5. software test case automatic generating method according to claim 4 is characterized in that step D comprises:
D1, the test case driving execution software under testing program that generates according to step C, and according to the path of the actual execution of the code record of plug-in mounting;
D2, the actual execution route of comparison and destination path judge whether actual execution route and destination path meet, if do not meet then execution in step C1; If meet, then return to the user with the test case storage that obtains and with it.
6. software test case automatic generating method according to claim 5 is characterized in that, said abstract syntax tree comprises object and the symbol table of representing type information.
7. a software test case automatic creation system is characterized in that, this system comprises:
Analysis module reads software under testing, and software source program to be measured is carried out lexical analysis, grammatical analysis and semantic analysis, generates abstract syntax tree and control flow graph;
Pre-processing module, the abstract syntax tree through the traversal analysis module generates carries out pre-service to software source program to be measured, and said pre-service comprises: discern original input, output variable, and the field of definition of original input variable is carried out space compression; The field of definition of original input variable, is further compressed the value space of original input variable according to the qualification effect of assignment in the calculation procedure and conditional statement by type of variables and the decision of operating system environment;
The test case generation module travels through the control flow graph that is generated, and cyclic search generates test case;
Said test case generation module further comprises:
The path generation unit, statement to be measured or condition to be measured according to the user provides generate the path of carrying out current statement to be measured or condition to be measured through traversal control flow graph;
Processing unit is used for calculating the rank of variable and correlated variables in the path that is generated, and the initialization condition counter, and the level definition of original input variable is 1, and the level definition of its dependent variable adds 1 for the maximum level of each variable in the definition expression formula of this variable;
Assignment is enumerated to the original input variable in the conditional statement in institute's generation pass in the assignment unit, and whether the value of judgment variable is empty;
Contain the unit, carry out subsume according to the value of variable in the assignment unit, and judge whether to occur new contradiction;
Trace unit, is recalled the value of variable for empty or when new contradiction occurring in the value of variable;
Judging unit, the current count value of condition counter be from increasing, and declare current count value and whether equal or exceed the conditional number on the path.
8. software test case automatic creation system according to claim 7 is characterized in that, this system further comprises:
Authentication module, the test case driving execution tested program of utilizing the test case generation module to generate, and, verify whether actual execution route conforms to destination path according to the path of the actual execution of plug-in mounting code record.
CN2007101775341A 2007-11-16 2007-11-16 Software test case automatic generating method and system Expired - Fee Related CN101436128B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2007101775341A CN101436128B (en) 2007-11-16 2007-11-16 Software test case automatic generating method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2007101775341A CN101436128B (en) 2007-11-16 2007-11-16 Software test case automatic generating method and system

Publications (2)

Publication Number Publication Date
CN101436128A CN101436128A (en) 2009-05-20
CN101436128B true CN101436128B (en) 2012-10-31

Family

ID=40710577

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2007101775341A Expired - Fee Related CN101436128B (en) 2007-11-16 2007-11-16 Software test case automatic generating method and system

Country Status (1)

Country Link
CN (1) CN101436128B (en)

Families Citing this family (59)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101894063B (en) * 2010-06-13 2012-09-26 北京北大众志微系统科技有限责任公司 Method and device for generating test program for verifying function of microprocessor
CN101901188B (en) * 2010-07-23 2012-02-01 哈尔滨工程大学 Reachable path-based software testing method
CN101923618B (en) * 2010-08-19 2011-12-21 中国航天科技集团公司第七一0研究所 Hidden Markov model based method for detecting assembler instruction level vulnerability
CN102385551B (en) * 2010-08-31 2015-04-29 西门子公司 Method, device and system for screening test cases
CN102567169B (en) * 2010-12-29 2014-02-26 无锡江南计算技术研究所 Test method and device of microprocessor
US8788239B2 (en) * 2011-02-11 2014-07-22 Fisher-Rosemount Systems, Inc. Methods, apparatus and articles of manufacture to test batch configurations
CN102103538A (en) * 2011-02-22 2011-06-22 南京航空航天大学 Method for testing palletizing robot control software based on Agent
CN102135937B (en) * 2011-03-15 2014-02-19 西安邮电大学 Pairwise overlay integrated software test suite generating method
JP2012212281A (en) * 2011-03-31 2012-11-01 Hitachi Government & Public Corporation System Engineering Ltd Range of influence setting device for program and range of influence specification method using the same and extraction method for program with ripple of influence
CN102243586B (en) * 2011-07-22 2015-02-04 于秀山 Method for automatically acquiring software function diagram
CN102306102B (en) * 2011-08-25 2017-09-12 中兴通讯股份有限公司 Program file automatic generation method and device
CN102436417B (en) * 2011-09-28 2014-08-06 于秀山 Code and function covering mapping system and covering mapping method thereof
CN102360336B (en) * 2011-10-20 2014-12-17 上海达梦数据库有限公司 Automatic testing system based on grammatical rules and method
CN103377045B (en) 2012-04-27 2016-12-14 国际商业机器公司 Method and system for Translation Verification Test
CN103425569B (en) * 2012-05-14 2016-09-28 中国银联股份有限公司 A kind of method and apparatus obtaining reuse degree of software module
CN102799520B (en) * 2012-06-27 2016-03-23 清华大学 For static check method and the device of source code pairing
CN102819489A (en) * 2012-07-05 2012-12-12 北京航空航天大学 Software reliability designing method driven by defects
CN103530223B (en) * 2012-07-06 2018-05-04 百度在线网络技术(北京)有限公司 A kind of method and device of automatically generating unit test use-case
CN102915271A (en) * 2012-10-31 2013-02-06 北京邮电大学 Method for optimizing unit regression test case set based on control flow diagram
CN103927473A (en) * 2013-01-16 2014-07-16 广东电网公司信息中心 Method, device and system for detecting source code safety of mobile intelligent terminal
CN103399528B (en) * 2013-03-06 2016-05-25 中国电力科学研究院 A kind of automatic generation method of Modbus slave station simulation system
CN103235759B (en) * 2013-05-15 2018-03-09 百度在线网络技术(北京)有限公司 Method for generating test case and device
CN105393226A (en) * 2013-07-23 2016-03-09 兰德马克绘图国际公司 Automated Generation Of Scripted And Manual Test Cases
CN103559044A (en) * 2013-11-20 2014-02-05 无锡儒安科技有限公司 Method and device for formalizing network control codes of wireless sensor
CN104035864B (en) * 2013-12-17 2017-10-20 北京邮电大学 A kind of path generating method based on contradiction fragment schema
CN103942140A (en) * 2013-12-19 2014-07-23 江苏锐天信息科技有限公司 Automatic testing program conversion method
CN104050082B (en) * 2014-06-17 2017-04-26 南京大学 Test data automatic generation method oriented toward modified condition/decision coverage
CN104317708B (en) * 2014-10-21 2017-06-13 北京邮电大学 The software test case automatic generating method and system of the interval arithmetic based on iteration
CN104484162B (en) * 2014-10-31 2018-04-03 国云科技股份有限公司 A kind of software test case designs write method
CN105988811B (en) * 2015-02-17 2019-09-03 华为技术有限公司 The method and apparatus for obtaining the kernel control flow chart of operating system
CN104636257B (en) * 2015-03-13 2017-10-27 胡兢玉 The DBAS automated testing method covered based on SQL
CN106681903B (en) * 2015-11-11 2020-05-12 阿里巴巴集团控股有限公司 Method and device for generating test case
CN105354035A (en) * 2015-11-17 2016-02-24 天津橙子科技有限公司 Method for compiling test case of web engineering
CN105867990A (en) * 2015-11-20 2016-08-17 乐视云计算有限公司 Software development integration method and device thereof
CN106844190B (en) * 2015-12-07 2022-06-07 中兴通讯股份有限公司 Automatic test script generation method and device
CN106959919B (en) * 2016-01-08 2022-01-28 阿里巴巴(中国)有限公司 Software testing method and device based on testing path diagram
CN107341399B (en) * 2016-04-29 2020-09-04 阿里巴巴集团控股有限公司 Method and device for evaluating security of code file
CN107608873B (en) * 2016-07-11 2021-05-25 珠海优特电力科技股份有限公司 Software testing method and system and testing platform
KR101989802B1 (en) * 2017-02-28 2019-06-18 주식회사 스패로우 Method for performing test using test case and apparatus for the same
CN107038119B (en) * 2017-03-31 2019-12-03 上海东软载波微电子有限公司 Automatic example generation method and device
CN108804304B (en) * 2017-05-05 2022-06-07 北京京东尚科信息技术有限公司 Test case generation method and device, storage medium and electronic equipment
CN107451057B (en) * 2017-07-31 2020-11-24 苏州浪潮智能科技有限公司 Branch determination method and device
CN109901984A (en) * 2017-12-08 2019-06-18 北京京东尚科信息技术有限公司 The method and apparatus for generating big data test case
CN110377493B (en) * 2018-04-12 2022-05-17 南京慕测信息科技有限公司 Unit test case optimization method facing code readability
CN108845933B (en) * 2018-05-24 2021-12-14 广东睿江云计算股份有限公司 Method and device for compiling and reviewing software test cases
CN109117363B (en) * 2018-06-28 2020-09-25 腾讯科技(深圳)有限公司 Test case generation method and device and server
CN109308260B (en) * 2018-08-30 2021-11-05 福建天泉教育科技有限公司 Method and terminal for automatically generating unit test code
CN109299003A (en) * 2018-08-31 2019-02-01 苏州洞察云信息技术有限公司 A kind of full-automatic testing case driving generation system towards complex software
CN109582559B (en) * 2018-09-28 2021-07-20 创新先进技术有限公司 System verification method and device, electronic equipment and storage medium
CN109656813A (en) * 2018-11-21 2019-04-19 恒为科技(上海)股份有限公司 A kind of test case operation method and device
CN109508296A (en) * 2018-11-22 2019-03-22 北京知道创宇信息技术有限公司 Data detection method, device and electronic equipment
CN109669436B (en) * 2018-12-06 2021-04-13 广州小鹏汽车科技有限公司 Test case generation method and device based on functional requirements of electric automobile
CN109815133B (en) * 2018-12-28 2022-08-09 达闼机器人股份有限公司 Software testing method and device, computing equipment and computer storage medium
CN110543421B (en) * 2019-08-31 2022-03-29 华南理工大学 Unit test automatic execution method based on test case automatic generation algorithm
CN111240772A (en) * 2020-01-22 2020-06-05 腾讯科技(深圳)有限公司 Data processing method and device based on block chain and storage medium
CN111475410B (en) * 2020-03-31 2024-01-09 北京经纬恒润科技股份有限公司 Test case generation method and device
CN111708542B (en) * 2020-06-24 2023-05-16 中国平安财产保险股份有限公司 Test case generation method, system, equipment and storage medium
CN113238932B (en) * 2021-04-30 2024-03-19 西南电子技术研究所(中国电子科技集团公司第十研究所) Automatic test case generation method
CN117171053B (en) * 2023-11-01 2024-02-20 睿思芯科(深圳)技术有限公司 Test method, system and related equipment for vectorized programming

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1767453A (en) * 2004-10-31 2006-05-03 中兴通讯股份有限公司 Automatic test method and system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1767453A (en) * 2004-10-31 2006-05-03 中兴通讯股份有限公司 Automatic test method and system

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
张威等.内存泄漏故障静态测试方法研究.《第四届中国测试学术会议》.2006,60-64. *
杨朝红、吕昌龄.ADTA—数据流覆盖测试工具.《装甲兵工程学院学报》.2001,第15卷(第1期),60-63. *
王建国等.一种综合数据流和控制流的协议测试集自动生成法.《清华大学学报(自然科学版)》.2000,第40卷(第3期),117-120,125. *

Also Published As

Publication number Publication date
CN101436128A (en) 2009-05-20

Similar Documents

Publication Publication Date Title
CN101436128B (en) Software test case automatic generating method and system
CN103473171B (en) A kind of fraction of coverage calling path based on function dynamically follows the tracks of method and device
CN109144882B (en) Software fault positioning method and device based on program invariants
CN103116493B (en) A kind of automatic mapping method being applied to coarse-grained reconfigurable array
CN103282878B (en) Based on the loop parallelization of Loop partitioning or index array
Guo et al. Exploiting community structure for floating-point precision tuning
CN105550268B (en) Big data process modeling analysis engine
CN105022691B (en) A kind of increasingly automated method for testing software based on uml diagram
CN102073589B (en) Code static analysis-based data race detecting method and system thereof
CN100414504C (en) Method and apparatus for recovering data values in dynamic runtime systems
CN103778061B (en) Automatically detection and the bearing calibration of Array Bound mistake
US7673295B1 (en) System and method for compile-time non-concurrency analysis
CN103713933B (en) Focus function, the assemblage method of variable, apparatus and system in computer program
CN105531672A (en) Parser generation
Girkar Functional parallelism: theoretical foundations and implementation
CN103645961B (en) The method for detecting abnormality of computation-intensive parallel task and system
CN101271397A (en) Recognition method of nested loop structure
CN108647146A (en) The method for generating test case of combined covering is judged based on correction conditions
CN103678121B (en) A kind of embedded binary software test case prioritization method
CN106294139B (en) A kind of Detection and Extraction method of repeated fragment in software code
CN105511867A (en) Optimization mode automatic generation method and optimization device
Ng et al. What does multi-objective optimization have to do with bottleneck improvement of production systems?
CN105302551A (en) Orthogonal decomposition construction and optimization method and system for big data processing system
CN105159835A (en) Pile inserting position obtaining method based on global superblock domination graph
CN102495800A (en) Iterative refinement method for abstractly valuing variables in Do statement

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20121031

Termination date: 20171116