CN104731695B - A kind of unit test system and method for supporting the input of table driving bottom - Google Patents
A kind of unit test system and method for supporting the input of table driving bottom Download PDFInfo
- Publication number
- CN104731695B CN104731695B CN201310703548.8A CN201310703548A CN104731695B CN 104731695 B CN104731695 B CN 104731695B CN 201310703548 A CN201310703548 A CN 201310703548A CN 104731695 B CN104731695 B CN 104731695B
- Authority
- CN
- China
- Prior art keywords
- function
- variable
- code
- input
- type
- 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
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a kind of unit test system for supporting table driving bottom to input and methods, including:Type resolver obtains type information for parsing dtd--data type definition;Tree table device, is made of Tree control and grid control;Valuator device, for the input value in tree table device to be assigned to variable;Bottom specification of variables device, for specifying bottom variable for user and tree table being added;Bottom input setting means, the bottom variable for inquiring user setting, and call valuator device and/or bottom function is allowed to continue to execute;Function call interception device, the calling for intercepting bottom function, and call bottom input setting means.The present invention makes bottom input by table driving, i.e., controls bottom input by table completely, simplify the management and maintenance of test data, improve the reusability of test data.The present invention solves the unit testing obstacle that the calling coupling of function is formed, and the efficiency of unit testing is made significantly to be promoted.
Description
Technical field
The present invention relates to software testing technologies, more particularly to software unit testing technology.
Background technology
Unit testing is to ensure code quality in software development process, promotes the important means of exploitation production capacity.
The basic skills of unit testing is to utilize Test driver code, and setting input and anticipated output execute and be tested journey
Whether sequence, automatic decision reality output meet expection.Input data and anticipated output are known as test case, that is, test number
According to this is the fundamental of unit testing work, and to the assignment procedure of input and judges the comparison procedure exported, then is unit
The core of measuring executing process.
One major obstacle of implementation unit test is bottom input problem.Bottom inputs, and bottom function is exactly called to obtain
The input obtained.Bottom function, the correlation function that exactly tested trial function is called.
C Plus Plus code below such as:
Function:Air-conditioning control program segment obtains environment temperature and calculates the time that refrigerator need to be run
Parameter:PWorkTime, output parameter preserve the time that refrigerator need to be run
It returns:Int types return to 0, otherwise return to non-zero value if function executes failure
WorkTime () is tested trial function, and function is to obtain environment temperature and calculate the time that refrigerator need to be run, and is taken
The mode of environment temperature is call function GetTemperature (), and GetTemperature () is by calling hardware temperatures meter
To obtain environment temperature.Herein, GetTemperature () is exactly the correlation function of tested function call, i.e. bottom letter
Number.Tested trial function and bottom function, which exist, calls coupled relation, and difficulty is caused to unit testing.How calling coupling is defined
The influence to unit testing that relationship is formed, is just more readily understood and dissolves influence?Basically, bottom function
A kind of input form of the output of GetTemperature () and tested trial function has no with the input transmitted by parameter
Essential distinction.For example, tested trial function is changed to:
Transmit by parameter, the function of code by the data for calling GetTemperature () to obtain originally
Logic and result of calculation are duplicate.So by the data for calling bottom function to obtain, these data are to bottom function
For, it is output, but for tested trial function, as parameter and a kind of input, referred to as bottom input.
For how to control the data by calling bottom function to obtain, allowed there are many method for example, writing a code
Bottom function generates various outputs and replaces actual object with simulated object alternatively, by Mock Object.These sides
Method, it is all cumbersome, it usually needs a large amount of code to be write or change, for example, to allow the stake code of GetTemperature ()
Five kinds of temperature are exported in five use-cases, need to judge to be which use-case is calling and exporting corresponding data in stake code,
15 line codes are taken around, if GetTemperature () function is also possible to more be tested function call,
Also to judge which tested trial function is calling in stake code, tool be typically only capable to generate the simple realization of stake and can not be automatic
The required output data of each use-case is generated, the workload for writing a code is huge.On the other hand, stake or simulated object production
Raw data can not usually put together with other data such as parameters, cause the use-case data of a tested trial function, storage
In many places, it is difficult to safeguard.In addition, for bottom function, actual code is directly invoked sometimes, to call stake or Mock sometimes
Object, this control and handoff procedure also increase workload.
Bottom inputs this concept, by the common number by calling the modes such as the data of bottom function acquirement and parameter to input
According to treating on an equal basis.Importantly, if you do not need to write a code or Mock Object, can accomplish that bottom directly is arranged
Input, and put together management with inputs such as parameters, then, the workload of unit testing will be greatly lowered.In particular, if
Bottom input can be driven by table, i.e., determine the value for needing which bottom input and bottom to input, needle by table
To compound type, determine which member needs that bottom input is arranged by table, bottom input, tool need not be arranged in which member
For body, implement function such as, then, the efficiency of unit testing work will be substantially improved:
A. if user's not setting bottom input in the table, calls actual code;
B. if user is provided with bottom and inputs in the table, bottom input is assigned to corresponding variable, is realized the bottom of to
The setting of layer input;
C. table supports any type, i.e. the bottom input of compound type can also be directly arranged in the table, by table
To determine which member needs that bottom input is arranged;
D. no matter whether bottom function whether there is, is isolated, and bottom can be arranged by table and input, user is not necessarily to
Additional setting.
In this way, in addition user need not go whether control bottom function calls actual code, and can as parameter,
Directly setting bottom inputs, then, the calling coupling of function is no longer just the obstacle of unit testing, and the efficiency of unit testing can be with
It increases substantially.
There is Individual cells testing tool to realize the tabular of fundamental type data, has also achieved and bottom inputted
Setting, bottom input can also move on in table, such as Guangzhou Kaile Software Technology Co., Ltd. issued in March, 2013
Unit test tool Visual Unit3.0 have bottom analog functuion, but there are important defects:
A. needing additional Test driver code, the working method of the bottom simulation of Visual Unit3.0 is:It is testing
Bottom simulation code is added in drive code set, when use-case executes, bottom simulation code is by bottom input data set by user
It is saved in memory, when calling bottom function, is inputted by inquiring these data to decide whether to be arranged bottom;
B. it moves the data in table manually;
C. the bottoms such as compound type, array, nil pointer cannot be inputted and is placed directly in table, for the bottom of compound type
Layer input, needs first to write code, compound type is decomposed into fundamental type, then the data of fundamental type are moved on in table,
This causes when in face of complicated type, it may be necessary to write and safeguard additional a large amount of Test driver codes;
D. to the assignment procedure of bottom input, using memory, integrally shallow copy mode is such as answered when in face of complicated object
The assigned result of miscellaneous C++ objects, variable may be incorrect, and also cannot be satisfied only certain members to composite variable
The demand of bottom input is set;
E. due to whether bottom input being arranged being realized by Test driver code, substantially test code
Driving, is not real table driving, when there is bottom simulation code in Test driver code, then no matter in table whether
Provided with value, the simulation to bottom function can be all caused, in this way, whether multiple use-cases in data form are unable to control bottom function
Actual code is called, i.e., can not accomplish that some use-cases setting bottom in table inputs, some use-cases call actual code.
In conclusion the prior art is not real table driving for bottom input, but use additional test
Drive code set drives, and when in particular for compound type, additional Test driver code quantity may be very much, increase debugging
With the cost of maintenance test drive code set, need to move the data in table manually, data form does not support the bottom of composite number type
Layer input, and bottom input memory copying assignment mode cause the assigned result of variable may be it is incorrect, can not
Meets the needs of setting unit member or only setting unit use-case.
Invention content
The technical problem to be solved by the present invention is to provide a kind of real unit testing system for supporting the input of table driving bottom
System and method, eliminate the defect of the prior art above-mentioned.In order to solve the above-mentioned technical problem, technical solution proposed by the present invention
It is:
A kind of unit test system for supporting table driving bottom to input, including Test driver code, which is characterized in that packet
It includes:
A:Type resolver obtains type information for parsing dtd--data type definition;
B:Tree table device, is made of Tree control and grid control, is used for tree-shaped display variable and its member, and provide table
Lattice fill in the input value of test case for user;
C:Valuator device, for the input value in the tree table device to be assigned to variable, the data class of the variable
Type includes fundamental type and compound type;
D:Bottom specification of variables device, the bottom variable for specifying bottom function for user, and by the bottom variable
Adding apparatus B, the bottom function refer to the function of tested function call, and the bottom variable includes one of following variable
Or the arbitrary combination of following variable:
The member that the return value of the bottom function, the output parameter of the bottom function, the bottom function are rewritten becomes
The global variable that amount, the bottom function are rewritten,
The data type of the bottom variable includes fundamental type and compound type;
E:Bottom input setting means, for inquiring whether user is provided with the bottom variable, and calling in device B
Device C and/or the bottom function is allowed to continue to execute;
F:Function call interception device, the calling for intercepting the bottom function, and calling device E.
Bottom variable described in device D can further include:For controlling whether the bottom function is directly skipped
Variable, the bottom function called number, the table described in device B can further include:Survey is filled in for user
The cell of the output valve of example on probation.
A kind of unit test method for supporting table driving bottom to input, including Test driver code, which is characterized in that packet
It includes:
A:Type analyzing step obtains type information for parsing dtd--data type definition;
B:Tree table step, the tree table are made of Tree control and grid control, are used for tree-shaped display variable and its member,
And provide the input value that table fills in test case for user;
C:Assignment procedure, for the input value in the tree table to be assigned to variable, the data type packet of the variable
Include fundamental type and compound type;
D:Bottom specification of variables step, the bottom variable for specifying bottom function for user, and by the bottom variable
Be added the tree table, the bottom function refers to the function of tested function call, the bottom variable include following variable it
The arbitrary combination of one or less variable:
The member that the return value of the bottom function, the output parameter of the bottom function, the bottom function are rewritten becomes
The global variable that amount, the bottom function are rewritten,
The data type of the bottom variable includes fundamental type and compound type;
E:Bottom input setting steps, for inquire user in the tree table whether be provided with the bottom variable, and
Invocation step C and/or the bottom function is allowed to continue to execute;
F:Function call interception step, the calling for intercepting the bottom function.
In addition, the invention also provides the sub-optimal scheme of the unit test system of aforementioned support table driving bottom input,
It is characterized in that, replacing feature B with feature G:
G:Table means, the input value for filling in test case for user.
Bottom variable described in device D, bottom input as above-mentioned.The present invention realizes the input of table driving bottom
Unit test system does not need additional Test driver code for the setting of bottom input;It need not move the data to manually
In table;Data form directly supports the bottom of composite data type to input;Support that only the few members to variable set bottom
Input;It supports only to input the part use-case setting bottom in table;Solve the assignment knot of the bottom input variable of the prior art
Fruit may incorrect problem.The present invention overcomes the major defect of the prior art completely.For the list developed using the present invention
First testing tool, user need not write and safeguard line code, only pass through the data in table, so that it may arbitrarily to control bottom
The behavior of function, for example, use-case 1 calls actual code, use-case 2 that the bottom input needed is directly arranged, or arbitrarily to compound
The member of type is arranged or is not provided with bottom input, i.e. bottom input is determined by table completely, realizes positive table driving of anticipating,
Bottom input is controlled by table completely, the management and maintenance of test data is simplified, improves the reusable of test data
Property.For the unit test tool for supporting table driving, other inputs such as bottom input and parameter are in same table middle pipe
The problem of reason, there is no the storages of the test data many places of a function.Using the present invention, the calling coupling of function is no longer just single
The obstacle of member test, the efficiency of unit testing can increase substantially.
The present invention in addition to solve the problems, such as bottom input table driving, can also solve the execution to bottom function control with
Decision problem:Using the variable whether directly skipped for controlling the bottom function, bottom function can be made not execute
Be not provided with bottom input directly skip, so as to solve some bottom functions collapse in measuring executing process cause test interruption
Problem;The called number of the bottom function is then whether bottom function to be executed and executed the judgement of number, be can be used for pair
The judgement for executing flow, is with a wide range of applications in fields such as communication, automatic controls.
Description of the drawings
Specific embodiments of the present invention will be described in further detail below in conjunction with the accompanying drawings:
Fig. 1 is that the overall of one embodiment of the present of invention constitutes schematic diagram;
Fig. 2 is the definition of some example ones;
Fig. 3 is that an example of data type shown in Fig. 2 has been used to be tested trial function;
Fig. 4 is the application effect schematic diagram of device 102 shown in FIG. 1;
The application effect schematic diagram of Fig. 5 devices 104 shown in FIG. 1;
Fig. 6 Fig. 7 Fig. 8 is the application effect schematic diagram compared with the prior art of the present invention, wherein:
Fig. 6 is the code sample of a tested trial function and bottom function;
Fig. 7 is the prior art and Test driver code comparison's schematic diagram after the application present invention, wherein Fig. 7 A are existing skills
The Test driver code of art, Fig. 7 B are using the Test driver code after the present invention;
Fig. 8 is the prior art and the list data schematic diagram after the application present invention, wherein Fig. 8 A are the tables of the prior art
Data, Fig. 8 B are using the list data after the present invention.
Specific implementation mode
Fig. 1 is that the overall of one embodiment of the present of invention constitutes schematic diagram, as shown in Figure 1, the present embodiment includes following dresses
It sets:Type resolver 101;Tree table device 102;Valuator device 103;Bottom specification of variables device 104;Bottom input setting dress
Set 105;Function call interception device 106.
The code sample of the present invention is write using C language or C Plus Plus, but does not represent the present invention and be only applicable to C language and C
++ language.It is to this hair that code sample cited by the present invention, to illustrate technical scheme of the present invention, does not represent just to just
Bright limitation.
Device 101 parses dtd--data type definition and obtains type information.Type information belongs to the generic term of this field, different
Programming language, type information may some difference, in general, type information includes:Typonym, memory size, respectively at
The member Name of member, typonym, offset, it is, of course, also possible to comprising other information, such as member function list.Here is to use
In an example of the data structure of description type information:
For describing a member, wherein:Type is the type of member;Name is the title of member;Offset is member
Offset.
For describing a type, wherein type is typonym, and size is the memory size of the example of type,
ChildCount is number of members, and pChilds is pointer to member's array.When for fundamental type, childCount 0,
PChilds is NULL.It is of course also possible to not use childCount and pChilds, but use a chained list or similar collection
It closes to replace.
Device 101 scans tested code, is parsed to the definition of each data type, obtains type information, can be with
Type information is preserved in the mapping table, use is inquired for other devices of the present invention.Since resolving belongs to general generation
Code parsing and technique of compiling, are not described in more detail here.
Device 102 is a tree table, is made of Tree control and grid control, and tree-shaped display variable and its member are used for,
And input value and output valve that table fills in test case for user are provided, in the basic embodiment of the present invention, tree table can
Not provide the function of filling in output valve, but if bottom variable includes the called number of bottom function, this is for judging
Whether called and call number the variable of bottom function, belongs to the output valve of use-case, then tree table, which needs to provide, fills in output valve
Cell, in order to just with explanation, hereinafter tree table using include output valve mode.Tree table both can be as general tree-like
Control is the same, is deployed into each leafy node, or packs up some node display portion nodes, can also be as general table control
Part equally increases unlimited number of row, to fill in unlimited number of use-case.
Fig. 2 Fig. 3 Fig. 4 shows the application effect of device 102, wherein Fig. 2 is the definition of some example ones, Fig. 3
It is a tested trial function for having used data type shown in Fig. 2, Fig. 4 is the application effect schematic diagram of device 102, that is, is directed to
Function shown in Fig. 3 establishes the interface schematic diagram of test data for user.User can be arranged with selecting unit lattice to be output and input
Value, can also increase row to establish more use-cases.
The variable is added according to the type information that the type queries device 101 of variable is obtained for each variable
Tree table, and the member that recursive scanning is all find type information according to the typonym of member, are added member as child node
Tree table checks member and the class of each node in order to facilitate user until the child node of fundamental type, i.e. tree table is fundamental type
The node of type, tree table can show name variable and typonym, can also be by for example aforementioned DataType of corresponding type information
The pointer of structure is stored in node, facilitates subsequent operation.Two row mode of a line may be used in table section, i.e., each knot
A line of the corresponding table section of point, each use-case two arrange, i.e. input row and output row, can also use two line mode of a row, i.e.,
Each node corresponds to two rows of table section, i.e. line of input and output is gone, and each use-case occupies a row.Device is quoted from below
When 102, it is all made of two row mode of a line.User can establish more use-cases by increasing row.As for the reality of tree table control
Existing process, and by the process of variable addition tree table, and to the normal operation of tree table, belong to the prior art, do not make here
It is described in detail.
Input value in tree table device is assigned to variable by device 103, and the data type of variable can be fundamental type, also may be used
To be compound type, i.e., device 103 is used for the data of fundamental type or compound type, is the change of fundamental type or compound type
Measure assignment.Since tree table itself is established according to the tree-like relationship of variable and its member, the data in tree table, with variable and its
Member has one-to-one relationship, and the realization approach of device 103 is exactly to carry out assignment operation according to this relationship, in total think of
Under road, a variety of realization processes with different details are can be designed that.
A kind of realization process is illustrated below, specific thinking is:Recursive scanning variable and its member, to needing to initialize
Variable or member's initialization, be not empty variable or member for corresponding input value, copy corresponding input value;The correspondence is defeated
Enter value, refer to the input value of variable or the corresponding current use-case of member in the tree table device, for example, tree table uses a line two
Row mode then corresponds to the value of the cell for the input row composition that input value refers to variable or the corresponding row of member and current use-case,
Some, which correspond to input values, may need by conversion, for example, integer type, what is filled in table may be character string, convert
For integer.For example, being directed to C or C Plus Plus, device 103 may be implemented in step below:
1)According to the typonym of variable, corresponding type information can be found, and whether be pointer or array.Array
Compound type can be considered as, such as int [10], the compound type containing 10 int subtype members can be considered as.
2)Variable is nullified, such as C language, for pointer, is then set as null pointer, non-pointer then calls memset ()
Empty memory.If it is sky that variable, which corresponds to input value, and the correspondence input value of all directly or indirectly members is also sky, then returns
It returns.
3)If the type of variable is pointer, and corresponding input value is null pointer, then is set as null pointer.It returns.
4)Variable is if necessary to voluntarily managing internal memory, such as the pointer of C or C++, then first to file memory.Apply for the mode of memory
Depending on language, such as C language, malloc (size) can be called, and for C++, then call new operators.
5)In the memory that corresponding input value is copied to variable, such as C language, it can copy with the following methods:
Character string:Strcpy (pDes, pSrc), wherein pDes is variable or the pointer of member, and pSrc is corresponding inputs
Value.
Integer int:* ((int*) pvar)=value, wherein pvar is variable or the pointer of member, and value is that correspondence is defeated
Enter value.
Other kinds of copy mode is similar, will not enumerate.
6)The pointer of member is calculated, and recurrence is executed according to the offset of member for each member of variable
State step.
Step 2)3)4)It can be regarded as initializing variable or member.It is the base of this field to variable or member's initialization
The process of plinth technology, different programming languages, different types, initialization may be different.For the language without using pointer, no
The step of needing to apply for memory and null pointer is arranged, under this situation, to the internal memory initialization of variable or member, be generally only by
Memory empties or is set as default value.
Some variable initializer shows of some language, it may be necessary to call constructed fuction, such as C Plus Plus contains empty letter
Several type, the initialization of object, preferably calls constructed fuction, in order to avoid due to the incorrect influence test execution mistake of virtual table
Journey under this situation, can replace step 4 with following methods)The new operators:One is established when parsing type information
A need call the list of the type of constructed fuction, and distribute a serial number to each type, and generate the generation of object generating function
The pointer of object generating function is passed to testing tool, the function of object generating function is by code when test code starts to execute
Pointer to object is generated according to the constructed fuction of type serial number call type, when to initialization of variable, calls object generating function
And type number is transmitted, the pointer to object established to obtain calling constructed fuction.For supporting the runtime to construct object
Language, such as Java language need not make in this way.
Abovementioned steps to variable initializer show, do not consider the situation of part assignment, i.e., only to the part of bottom variable at
The situation of member's assignment.For needing the bottom variable of part assignment, need to modify initialization procedure, for example, for multiple
The bottom variable of type is closed, only to being initialized with the variable or member that correspond to input value, dependent variable or member are not required to
It initializes, to make other members keep original value.
Some rules can be formulated for list data, for example, for certain special values, can arrange to indicate the value
Symbol such as indicates null pointer with NULL, in example of the invention, in tree table or table, NULL is used to indicate null pointer.
For the simplicity realized, in above-mentioned steps 5), usually only processing fundamental type, if tree table allow directly against
Compound type fills in complex data, then this data are typically by the data of certain regular layouts, cell as shown in Figure 4
Data before executing assignment procedure, can be decomposed for this situation and be assigned to leafy node correspondence by the data in 401
Cell, i.e. the corresponding cell of member of fundamental type, so as to make step 5) only handle fundamental type.
Device 104 is used to specify the bottom variable of bottom function for user, and by bottom variable adding apparatus 102, bottom
Function, refers to the function of tested function call, bottom variable, refers to the variable for calling bottom function to be exported or for controlling
Or judge the variable that bottom function executes, including:The return value of bottom function, the output parameter of bottom function, bottom function change
Global variable that the member variable write, bottom function are rewritten, for controlling variable that whether bottom function directly skip, for sentencing
The variable of the disconnected called number of bottom function, wherein preceding four output for belonging to bottom function, for tested trial function,
It is then input, i.e. bottom inputs, and when using the present invention, can select to support one of these variables or arbitrary group of these variables
It closes, latter two for controlling bottom function or judging.The data type of bottom variable includes fundamental type and compound type.It is right
In the data that bottom function should not be rewritten, for example, input parameter or pass value parameter, the member variable that bottom function is not rewritten or
Global variable is not usually required to as bottom variable, and when using the present invention, it is also feasible that these variables, which are also classified as bottom variable,
, it is only upper nonsensical in test.One bottom function, it is understood that there may be numerous output variables, but it is not necessarily all equal
As bottom variable, the variable being related to only is needed in test process, that is, the implementation procedure of tested trial function need to be to be used
Variable is just needed as bottom variable.
Device 104 provides an interactive interface, specifies bottom variable for user, and the bottom variable that user is specified is added
Tree table, a kind of realization method are to provide a simple interface, and bottom function name, the type and name of bottom variable are filled in by user
Claim, wherein title can fixed rule settings according to the appointment, if return indicates return value, arg1 indicates first parameter, in order to just
Different parameters is identified in user, for famous parameter, more preferably mode is to use original parameter name.Then bottom user filled in
Tree table is added in layer variable, in order to just to distinguish bottom variable and its dependent variable, when tree table is added, arrange naming rule, example
Such as:Func () return, the return value of representative function func (), first ginseng of func () arg1, representative function func ()
Number, after func () gVar indicates call function func (), the end value of global variable gVar.It can also be by a bottom function
Bottom input one tree structure of composition, if func () is used as root node, below there are three child node:Return, arg1,
gVar。
In order to further enhance efficiency, device 104 is more preferably achieved in that:It parses tested code and obtains possible bottom
Layer variable list is selected for user, a more preferably examples of interfaces of realization method in Fig. 5.As shown in figure 5, device 104 arranges automatically
Go out the data such as type, the title of possible bottom variable to select for user.A kind of realization approach is solved to tested code
Analysis, record the returns Value Types of each function, go out ginseng and type, may rewrite member variable and type, may rewriting it is complete
Office's variable and type, and show the code for being tested trial function, for user when double-clicking the called code of bottom function, display may
Bottom variable and its type, user only need to choose bottom variable to be used, you can complete setting.
The option for allowing user to choose whether initialization can also be increased by setting 104, so as to the variable for only needing part assignment,
In the assignment procedure of device 103, the member for bottom input need not be arranged keeps initial value constant without initialization.
After user completes the setting of bottom variable, tree table is added in bottom variable by device 104, and user can be in tree table
For each use-case, specific value is set.
Device 105 is used to inquire whether user to be provided with bottom variable and calling device 103 and/or allowed in device 102
Bottom function continues to execute.Device 105 can be implemented as a function, and here is an exemplary statement of the function:
long_SubInput(const char*fn,void**prt,void*data,long count);
First parameter transmits bottom function name;Second parameter is the second rank pointer for preserving return value;Third
Parameter is to preserve out the array of ginseng information, goes out to join the serial number that information may include parameter, the address of parametric variable;4th parameter
Pass out the quantity of ginseng.Return value is used for transmitting whether user inputs in current use-case provided with bottom, for example, user setting
Bottom inputs, then returns to 1, otherwise return to 0.
As under which situation allow bottom function continue to execute, can lay down a regulation in the application, can also by with
Family selects.In general, once some bottom variable is provided with value in tree table, bottom function can be executed no longer, below
Further realization approach is provided according to this rule:
1)If there is no the bottom variable of bottom function in tree table, 0 is returned to, bottom function continues to execute;
2)If there is the bottom variable of bottom function in tree table, whether inquiry user under current use-case is provided with value,
If all bottom variables of the bottom function are not provided with value, 0 is returned to, bottom function continues to execute;
3)The value of user setting is assigned to variable by calling device 103, and returns to 1, and bottom function no longer executes.It is filled calling
When setting 103, return value and the pointer for going out ginseng are transmitted by parameter, and the address of member variable and global variable, are generally required another
Outer acquisition.The present invention can support section bottom variable will be at if need to support for example, only support return value and/or go out ginseng
Bottom variable as bottom function of member variable and global variable, then, the step of needing the address of addition acquirement global variable,
For example, adding some codes in Test driver code, the address for transmitting each global variable is simultaneously saved in somewhere.It is right
In member variable, can be obtained according to the type information of tested class, the pointer of tested object and the inquiry of member variable name.It is right
The address for going out in return value address and respectively ginseng, further illustrates when illustrating device 106.
It is previously used for the variable whether control bottom function is directly skipped, referred to herein as jumps out variable, for supporting directly
Bottom function is skipped, abnormal bottom function is will produce commonly used in skipping to call under unit testing environment, for example, interface class
Function may be because interface resources under unit testing environment there is no causing to execute collapse, when this class function is produced to survey
When trying significant output, it can be skipped by the way that bottom variable is arranged, otherwise, can be controlled using variable is jumped out, jump out change
Amount can use types, the aforementioned _ SubInput example functions such as boolean, int, long that can increase the inquiry to jumping out variable,
If user setting jumps out variable, regardless of whether returning to 1 provided with other bottom variables, bottom function is made no longer to hold
Row.
It is previously used for judging the variable of the called number of bottom function, referred to herein as judgment variable, for supporting to bottom
The judgement of the call number of function.Judgment variable can use the integer type of int or long types etc.Become with other bottoms
Amount is different, and judgment variable is used for after the execution of tested trial function, judges whether bottom function is called and call number, this is being surveyed
It is the expected output of one kind in example on probation rather than inputs, therefore, if having used judgment variable, needs to provide in device 102
The cell of output valve is filled in, for example, providing output row or output row.It is a realization think of of the application of judgment variable below
Road:When aforementioned _ SubInput example functions execute, for one counter of current bottom function setup, _ SubInput is executed
Once, then count is incremented for current bottom function, increases the judgement to call number in Test driver, that is, reads in tree table and use
Family, if do not met, exports test crash information to the setting value of judgment variable and compared with the execution number recorded.By
It is fundamental type in judgment variable, comparison procedure belongs to the prior art, is not described herein in detail.
Device 106 is used to intercept the calling of the bottom function, i.e., is not directly to execute when bottom function is called,
But jump to device 105.Interception to function call is any technique commonly known, is that those skilled in the art may be implemented
, there are many modes of realization, such as:Function hook, instruction redirect, are inserted into interception code, code is replaced etc..
Function hook is a kind of technology having history for many years, if Windows is for intercepting API and the Hook Function of message,
It is not described in detail here.
It is also common technology that instruction, which redirects, extremely common in debugging acid, such as C or the code of C Plus Plus exploitation, is compiled
The call address after function call instruction after translating by changing machine code, you can realize that instruction redirects.For unit testing work
For tool, the executable file generated after tested code compiling link can be analyzed, find out tested function pair and answer
Machine code in the instruction of bottom function call and preserve its position, former call address, the information such as address of output parameter,
In measuring executing process, realize that the interception to bottom function, calling device 105 simultaneously transmit return by changing call address
Address and go out to join information.It, can when can also obtain calling device 105 with same method for using function hook interception mode
The return address and go out to join information that energy needs.Analysis to executable file is the reverse operation to compiling and link process, root
According to the characteristic and invocation protocol of compiler linker, call instruction in machine code and the instruction before and after call instruction are divided
Analysis, belongs to the prior art, is not described herein in detail.
It refers to the entrance insertion code realization interception function in bottom function to be inserted into and intercept code.Relative to first two side
Method, be inserted into intercept code may be implemented more directly to control bottom function, and by interception code provide calling device 105 when
May need return value address and go out to join information, be below be inserted into intercept code a kind of implementation example:
Wherein, structure SUB_INPUT_DATA is defined as preserving out ginseng serial number and address:
Function _ SubInput () is a kind of realization of device 105.Code is intercepted as to how being inserted into, this is general generation
Code parsing and code instrumentation technology, belong to the prior art, are not described herein in detail.
It refers to the calling that will be replaced with to the calling of bottom function to replacing function that code, which is replaced, is to have to adjust instead of function
With the function for replacing former bottom function of 105 function of device.Function is replaced it is generally necessary in addition write or generated by tool, instead of
Function can be with interception code come calling device 105, and the realization for intercepting code is similar to aforementioned insertion interception code section
Example.Code replace a kind of thinking be:If bottom function is not implemented or is isolated, with the function of the same name with bottom function
Instead of bottom function;Otherwise use the function not of the same name with bottom function as replace function, and directly change tested code or
Tested code is changed indirectly by precompile mechanism, will replace with the calling to replacing function to the calling of bottom function, i.e.,
There are two types of situations for common code replacement:
1)Former bottom function is not implemented or needs to be isolated, then also has the function of stake instead of function, and code is tested to allow
Function of the same name can be can be implemented as instead of function, i.e. original shape and former bottom function original shape is complete by compiling link, under this situation
Complete the same function will be directly invoked instead of function in measuring executing process, and the code of tested trial function need not be changed, in this way
Not only piling had been completed, but also has realized calling and intercepts.
2) former bottom function has been realized and need not be isolated, then should be not of the same name with bottom function instead of function, writing or
It generates after replacing function, tested code is changed by hand or directly by tool, or utilize the precompiles mechanism such as macro grammer,
The calling to replacing function will be replaced with to the calling of bottom function, and under this situation, former bottom should be generally called instead of function
Layer functions, to call former bottom function when needed according to the setting of user.
Writing or generating instead of function, and test code call is allowed to belong to the prior art instead of the process of function, this
In be not described further.
Above-mentioned several interception modes can be used alone, and more preferably mode is comprehensive use, for example, for user-defined
And the function being not isolated from uses generation using interception code means are inserted into for user-defined but unrealized or segregate function
Code alternative redirects mode or function hook mode for library function using code alternative or instruction.
Here is the specific work process of one embodiment of the present of invention:
Device 101 parses type information and is used for other devices.User is by device 104, for one or more bottoms
Function is respectively set one or more bottom variables, is automatically added in device 102.User is in device 102 to bottom variable
Assignment is carried out, for needing the use-case of execution bottom function source code, then not to bottom variable assignments.Measuring executing process
In, when tested code calls bottom function, is intercepted by device 106 and call simultaneously calling device 105,105 query tree of device
Bottom variable in table and user's setting value continue to execute original function if user does not set the bottom variable of current use-case,
Otherwise calling device 103 carries out assignment and returns.For the bottom variable of compound type, user can only to it is therein individually at
Member's assignment, i.e., to bottom variable part assignment, to keep other members of variable constant.
Fig. 6 Fig. 7 Fig. 8 is the application effect schematic diagram compared with the prior art of the present invention, wherein:Fig. 6 is one tested
The code sample of trial function and bottom function;Fig. 7 is that the prior art is illustrated with the Test driver code comparison after the application present invention
Figure, wherein Fig. 7 A are the Test driver codes of the prior art, and Fig. 7 B are using the Test driver code after the present invention;Fig. 8 is existing
There are technology and the list data schematic diagram after the application present invention, wherein Fig. 8 A are the list datas of the prior art, and Fig. 8 B are applications
List data after the present invention.As shown in fig. 6, function mysub () is bottom function, function subinputtest () is tested
Trial function.As shown in figure 8, under the premise of the bottom input data for needing to set is same or similar, as shown in Figure 7 B, this is utilized
Invention, Test driver code need not increase additional code, and as shown in Figure 7 A, the prior art needs to add largely test and drives
Dynamic code, in Fig. 7 A, the 3rd to the 15th row totally 13 line codes, are bottom simulation code, wherein only the 15th row is given birth to by tool
At other are required to hand-coding, and need to move the data in table by hand.It can be seen that from the comparison of Fig. 7 and utilize this hair
It is bright, it can be to avoid writing the code largely inputted for realizing bottom, only this item, so that it may unit testing is substantially improved
Efficiency.
For the unit test method of support table driving bottom input of the present invention, implementation step has been contained in
In the explanation of front, it is not repeated.
The present invention can not use tree table device 102, and be replaced with general table.This is a kind of sub-optimal scheme,
It can realize the main effect of the present invention, it is still, whole using forms mode or by variable and its all direct or indirect members
Be added table or only be added variable itself and be added without member, when data type is very complicated, both modes to user all
Inconvenience, the former causes line number in table too many, especially for the type containing the member for being directed toward itself pointer, may cause
Endless loop, the difficulty that the latter then fills in data are larger.If be all added using by variable and its all direct or indirect members
The mode of table, then, implement the process of the present invention, except 102 part of device is changed to use table, the embodiment of other devices
It is the same.If in such a way that only addition variable itself is added without member, it is possible to by the composite number in cell
According to the data for being decomposed into fundamental type, the data in cell 401 as shown in Figure 4 can first resolve into the number of fundamental type
According to the data after these decomposition, are corresponding with the member of variable, device 103 still can carry out assignment by mode above-mentioned.
Above example be only the present invention better embodiment, be only to illustrate the present invention and it is unrestricted, to the present invention
Modify, deform or equivalent replacement without departing from the spirit and scope of the present invention, should all be covered by the scope of the present invention it
It is interior.
Claims (10)
1. a kind of unit test system for supporting table driving bottom to input, including Test driver code, which is characterized in that packet
It includes:
A:Type resolver obtains type information for parsing dtd--data type definition;
B:Tree table device, is made of Tree control and grid control, is used for tree-shaped display variable and its member, and provides table confession
User fills in the input value of test case;
C:Valuator device, for the input value in device B to be assigned to variable, the data type of the variable includes basic class
Type and compound type;
D:Bottom specification of variables device, the bottom variable for specifying bottom function for user, and the bottom variable is added
Device B, the bottom function refers to the function of tested function call, the bottom variable include one of following variable or with
The arbitrary combination of lower variable:
The return value of the bottom function, the output parameter of the bottom function, the member variable of bottom function rewriting, institute
The global variable of bottom function rewriting is stated,
The data type of the bottom variable includes fundamental type and compound type;
E:Whether bottom input setting means are provided with the bottom variable and calling device for inquiring user in device B
C and/or the bottom function is allowed to continue to execute;
F:Function call interception device, the calling for intercepting the bottom function, and calling device E.
2. unit test system according to claim 1, which is characterized in that the type information includes:It is typonym, interior
Deposit size, the member Name of each member, typonym, offset.
3. unit test system according to claim 1, which is characterized in that the valuator device includes:Recursive scanning becomes
Amount and its member, the variable or member initialized to needs initialize, are not empty variable or member for corresponding input value, copy
Shellfish corresponds to input value;The corresponding input value refers to the input of variable or the corresponding current use-case of member in the tree table device
Value.
4. unit test system according to claim 1, which is characterized in that the bottom variable described in device D further wraps
It includes:The variable whether directly skipped for controlling the bottom function.
5. unit test system according to claim 1, which is characterized in that the bottom variable described in device D further wraps
It includes:The called number of the bottom function, the table described in device B further comprise:The defeated of test case is filled in for user
Go out the cell of value.
6. unit test system according to claim 1, which is characterized in that device D further comprises:Parsing is tested generation
Code obtains possible bottom variable list and is selected for user.
7. according to the unit test system described in claim 1 to 6 any claim, which is characterized in that device F includes following
The arbitrary combination of one of step or following steps:
Function hook, for jumping to device E when the bottom function is called;
Instruction redirects, for jumping to device E before the bottom function is called;
It is inserted into and intercepts code, intercept code for being inserted into the bottom function, the interception code is in bottom function reality
Modern code executes before executing, and calling device E;
Code is replaced, described to replace function for that will replace with the calling to replacing function to the calling of the bottom function, is
Refer to the function instead of the bottom function with calling device E functions.
8. unit test system according to claim 7, which is characterized in that the code, which is replaced, includes:If the bottom
Layer functions are not implemented or are isolated, then replace the bottom function with the function of the same name with the bottom function;Otherwise with institute
It states bottom function function not of the same name and replaces function as described, and directly change tested code or by between precompile mechanism
Modification tested code is connect, the calling of the bottom function will be replaced with to the calling instead of function.
9. unit test system according to claim 1, which is characterized in that replace feature B with feature G:
G:Table means, the input value for filling in test case for user.
10. a kind of unit test method for supporting table driving bottom to input, including Test driver code, which is characterized in that packet
It includes:
A:Type analyzing step obtains type information for parsing dtd--data type definition;
B:Tree table step, the tree table are made of Tree control and grid control, are used for tree-shaped display variable and its member, and carry
The input value of test case is filled in for user for table;
C:Assignment procedure, for the input value in the tree table to be assigned to variable, the data type of the variable includes base
This type and compound type;
D:Bottom specification of variables step, the bottom variable for specifying bottom function for user, and the bottom variable is added
The tree table, the bottom function refers to the function of tested function call, the bottom variable include one of following variable or
The arbitrary combination of following variable:
The return value of the bottom function, the output parameter of the bottom function, the member variable of bottom function rewriting, institute
The global variable of bottom function rewriting is stated,
The data type of the bottom variable includes fundamental type and compound type;
E:Bottom inputs setting steps, for inquiring whether user is provided with the bottom variable, and calling in the tree table
Step C and/or the bottom function is allowed to continue to execute;
F:Function call interception step, the calling for intercepting the bottom function.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310703548.8A CN104731695B (en) | 2013-12-19 | 2013-12-19 | A kind of unit test system and method for supporting the input of table driving bottom |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310703548.8A CN104731695B (en) | 2013-12-19 | 2013-12-19 | A kind of unit test system and method for supporting the input of table driving bottom |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104731695A CN104731695A (en) | 2015-06-24 |
CN104731695B true CN104731695B (en) | 2018-11-09 |
Family
ID=53455605
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310703548.8A Active CN104731695B (en) | 2013-12-19 | 2013-12-19 | A kind of unit test system and method for supporting the input of table driving bottom |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104731695B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106055481B (en) * | 2016-06-02 | 2020-03-27 | 腾讯科技(深圳)有限公司 | Method and device for testing computer program |
CN111159033B (en) * | 2019-12-25 | 2023-07-04 | 口碑(上海)信息技术有限公司 | Software testing method and device |
CN112181851B (en) * | 2020-10-27 | 2023-07-28 | 北京字跳网络技术有限公司 | Software testing method, device and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1908892A (en) * | 2005-08-01 | 2007-02-07 | 王彤 | System and method for test examples design |
CN1949186A (en) * | 2006-11-17 | 2007-04-18 | 深圳市领测科技有限公司 | Program testing system and mapping method for said program testing system |
CN101110055A (en) * | 2007-08-31 | 2008-01-23 | 中兴通讯股份有限公司 | Device for implementing general use pile function in unit test and implementing method thereof |
CN101110024A (en) * | 2007-08-14 | 2008-01-23 | 中兴通讯股份有限公司 | Unit test system and method thereof |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080115114A1 (en) * | 2006-11-10 | 2008-05-15 | Sashank Palaparthi | Automated software unit testing |
US8954929B2 (en) * | 2010-03-29 | 2015-02-10 | Microsoft Corporation | Automatically redirecting method calls for unit testing |
-
2013
- 2013-12-19 CN CN201310703548.8A patent/CN104731695B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1908892A (en) * | 2005-08-01 | 2007-02-07 | 王彤 | System and method for test examples design |
CN1949186A (en) * | 2006-11-17 | 2007-04-18 | 深圳市领测科技有限公司 | Program testing system and mapping method for said program testing system |
CN101110024A (en) * | 2007-08-14 | 2008-01-23 | 中兴通讯股份有限公司 | Unit test system and method thereof |
CN101110055A (en) * | 2007-08-31 | 2008-01-23 | 中兴通讯股份有限公司 | Device for implementing general use pile function in unit test and implementing method thereof |
Non-Patent Citations (2)
Title |
---|
"ATC***软件自动化单元测试工具的研究与实现";张秀琼;《万方数据》;20070807;第三至五章 * |
"c/c++单元测试底层模拟技术";刘跃勇 等;《计算机***应用》;20121130;第21卷(第11期);第156-160页 * |
Also Published As
Publication number | Publication date |
---|---|
CN104731695A (en) | 2015-06-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR102323378B1 (en) | Data processing methods and related products | |
CN101589366B (en) | Parallelization and instrumentation in a producer graph oriented programming framework | |
CN102915242A (en) | Method for implementing code programming by graphical operations | |
CN107066256B (en) | Object change model modeling method based on tense | |
CN105094818B (en) | Natural resources integrated application construction method and system based on SOA | |
CN103019742B (en) | A kind of real time workshop method in many DSP platform | |
Miremadi et al. | A BDD-based approach for modeling plant and supervisor by extended finite automata | |
US20230162048A1 (en) | Method for adapting deep learning framework to hardware device based on unified backend engine | |
CN106021816A (en) | Method for achieving distributed system behavior simulated analysis tool based on behavior tree | |
Torgo | An infra-structure for performance estimation and experimental comparison of predictive models in r | |
CN104731695B (en) | A kind of unit test system and method for supporting the input of table driving bottom | |
CN110287088B (en) | Automatic testing method based on dynamic UI model | |
CN112199086A (en) | Automatic programming control system, method, device, electronic device and storage medium | |
CN110673844A (en) | Image processing software development method and system | |
Xu et al. | Using adaptive agents to automatically generate test scenarios from the UML activity diagrams | |
CN106250134B (en) | The code automatic generation method of single language | |
CN110109816A (en) | Test cases selection method and apparatus | |
CN107153749A (en) | A kind of satellite matrix cable junctions design tool and design method | |
Isaac | The ABM template models: A reformulation with reference implementations | |
CN115185539A (en) | Method, device and storage medium for generating executable dynamic link library file | |
CN106096159B (en) | A kind of implementation method of distributed system behavior simulation analysis system under cloud platform | |
Kirshin et al. | A UML simulator based on a generic model execution engine | |
CN104731700B (en) | A kind of unit test system and method for supporting table driving local data | |
CN110362334A (en) | C++ Object Life Cycle management method, the equipment, medium of secondary development language | |
Niere et al. | Using Fujaba for the development of production control systems |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Address after: 510315 UP Chi Chi C2-209, 29, West Road, Hongwei new village, Haizhuqu District, Guangzhou, Guangdong. Applicant after: Guangzhou Kaile Software Technology Co., Ltd. Address before: 510630 303, room 244, five mountain road, Tianhe District, Guangzhou, Guangdong. Applicant before: Guangzhou Kaile Software Technology Co., Ltd. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant |