CN100511135C - Unit test system and method thereof - Google Patents

Unit test system and method thereof Download PDF

Info

Publication number
CN100511135C
CN100511135C CNB2007100757420A CN200710075742A CN100511135C CN 100511135 C CN100511135 C CN 100511135C CN B2007100757420 A CNB2007100757420 A CN B2007100757420A CN 200710075742 A CN200710075742 A CN 200710075742A CN 100511135 C CN100511135 C CN 100511135C
Authority
CN
China
Prior art keywords
unit
information
test
under test
information extraction
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
Application number
CNB2007100757420A
Other languages
Chinese (zh)
Other versions
CN101110024A (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.)
State Grid Shanghai Electric Power Co Ltd
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CNB2007100757420A priority Critical patent/CN100511135C/en
Publication of CN101110024A publication Critical patent/CN101110024A/en
Application granted granted Critical
Publication of CN100511135C publication Critical patent/CN100511135C/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

The utility model discloses a unit test system and a method thereof. The system comprises a unit to be tested (105), a buffer unit (102), a general driver element (101), a testing control unit (106), an information extraction unit (103). The utility model can effectively improve the efficiency and the quality of the unit test as well as decrease the labor cost. Meanwhile, the test case can be revised and re-used continuously, so as to greatly reduce the duplication of labor.

Description

A kind of unit test system and method
Technical field
The present invention relates to software testing technology, a kind of method that in unit testing, realizes the general driving function of more specifically saying so.
Background technology
The workload of writing of driving function is bigger in the unit testing, the corresponding at least driving function of each tested function, and need regular modification compiling, influence unit testing efficient.Address this problem at present basically based on two thinkings: 1, write with script by hand.Advantage is to repeat compiling, is applicable to that tested code change is few, and the many scenes of driving function change.Shortcoming is to write workload not reduce, and the user need learn a kind of new script, and learning curve is long.2, generate driving function automatically, advantage is to have reduced the workload that driving function is write, and shortcoming is the complicacy that has increased testing tool, can both generate driving function automatically if desired under various translation and compiling environments, be easy to produce compile error, to testing tool require high.
Summary of the invention
In view of this, the technical problem to be solved in the present invention provides a kind of unit test system and method, can reduce in the unit testing process driving function and write workload, and the realization difficulty of this method is less, can realize under various operating systems, translation and compiling environment.
For realizing the technical problem to be solved in the present invention, unit test system of the present invention comprises: unit under test, buffer cell, general driving unit, unit of testing and controlling, information extraction unit; Described information extraction unit is input with the unit under test, is used to extract the information of unit under test; Described unit of testing and controlling is used for the information of the unit under test of recalls information extraction unit acquisition, and before test the information of calling is put into buffer cell, and controls described general driving unit and test; The general driving unit obtains information from the buffering unit, and puts into the test environment of setting, calls tested function, and output valve is put into buffer cell; Described unit of testing and controlling also is used for extracting the judgement that output valve is finished test result from the buffering unit.
Preferably, the information extracted from unit under test of described information extraction unit comprises: the data structure of unit under test, function parameter, rreturn value, global variable.
Preferably, also comprise the symbol table unit, be used for the information that the packaging information extraction unit extracts, and external interface is provided.
Preferably, described information extraction unit is specifically extracted the information of unit under test by the static scanning analysis mode.
The unit test method that the present invention proposes comprises following treatment step:
1) information extraction unit information extraction from unit under test;
2) unit of testing and controlling is used for recalls information extraction unit acquired information and deposits buffer cell in;
3) the general driving unit obtains information from the buffering unit, and puts into the test environment of setting, calls tested function, carries out test process, and deposits output valve in buffer cell;
4) unit of testing and controlling also is used for extracting the judgement that output valve is finished test result from the buffering unit.
Preferably, the information of extracting in the described step 1) comprises: the data structure of unit under test, function parameter, rreturn value, global variable.
Preferably, comprise also after the described step 1) that information extraction unit deposits the information of extracting in the treatment step of symbol table unit.
Preferably, information extraction unit adopts the static scanning analysis mode to extract the information of unit under test in the described step 1).
The unit test system and the method that adopt the present invention to propose can effectively improve the efficient and the quality of unit testing, reduce human cost, and test case can constantly revise multiplexingly, significantly reduce the duplication of labour.Specifically comprise following advantage:
1, by tested module is extracted structural information, make the user not need to be concerned about the structure of program;
2, driving function has only one, does not need to write a large amount of driving functions and test script, has reduced the technical ability requirement to the tester;
3, responsibility is clear, and the user only need provide function needed inputoutput data, and other are all handled by the general driving function, help realizing the unit testing of data-driven, and reusability and dirigibility improve greatly.
If 4 by visualization interface editor inputoutput data, ease for use will improve greatly.
5, after tested program once compiles, can create and move a plurality of test cases flexibly, reduce the compiling number of times of system;
6, tested program can be on target machine, also can be on PC, and can the multiple test environment of flexible adaptation.
Description of drawings
Fig. 1 is a preferred embodiment of the present invention unit test system structural representation;
Fig. 2 is the tested function call process flow diagram of preferred embodiment of the present invention unit test method.
Embodiment
Core concept of the present invention is: replace a large amount of driving functions with a general driving function, and with the direct access program storehouse of the method for similar compiler, thus can be the different driving function unification of various statements to same driving function.
For making purpose of the present invention, technology and advantage clearer, the present invention is described in further detail below in conjunction with accompanying drawing.
Fig. 1 shows according to unit test system modular structure synoptic diagram of the present invention, and the main modular structure among the present invention has been described.The present invention includes general driving unit 101, buffer cell 102, information extraction unit 103, symbol table unit 104, unit under test 105, unit of testing and controlling 106.
Wherein, general driving unit 101 is major parts of the present invention, and its main and buffer cell 102 carries out alternately.It (comprising: the value of parameter, global variable), by certain method value is put into current execution environment, call tested function, and the output valve of tested function (is comprised from the input value that buffering unit 102 obtains tested function; Rreturn value, go out the value of ginseng, global variable) put into buffer cell 102.
Buffer cell 102 modules provide an information that is used for storage function parameter, global variable, rreturn value, carry out before, carry out back result's buffer zone, and the API that visits this buffer zone, this module has solved the storage problem of data.Mainly comprised following field in the buffer zone structure: the index of Index-parameter, the title of VarName-global variable, size-shared byte-sized, pointerflag-whether be pointer (array and pointer are handled equally), data-be used for the depositing data block of numerical value.Unit of testing and controlling 106 need be put into buffer zone to the value of tested function parameters, global variable before test; After carrying out general driving unit 101, unit of testing and controlling 106 need obtain from buffering unit 102 tested function rreturn value, go out the value of ginseng, global variable, whether judged result correct.
Information extraction modules 103 is input with unit under test 105, by unit under test 105 being analyzed (as the tested module source file is carried out the static scanning analysis, but the present invention also goes for other forms of analytic process), obtain data structure, function parameter, the rreturn value of unit under test (105), the information of global variable, and by these information of symbol table unit 104 accesses, these information are bases of general driving unit 101 operations.
Symbol table unit 104 has encapsulated the information that information extraction unit 103 is obtained, and external interface is provided, and obtains the information such as type, size of tested function parameters, rreturn value, global variable for other modules.
The tested function of unit under test 105 representatives was the source file that has comprised one group of tested function before compiling, was one group of binary code that is generated by tested function source file after compiling.
Unit of testing and controlling 106 is to realize the module of test control, its recalls information extraction unit 103 obtains data structure, function parameter, the rreturn value of unit under test 105, the information of global variable, before test, the input value of tested function (value of parameter, global variable) is put into buffer cell 102, and calling back, general driving unit 101 obtains tested function from buffering unit 105 rreturn value, the value that goes out ginseng, global variable, whether judged result is correct.Because the design of buffer cell has been arranged, unit of testing and controlling is easy to accomplish the automatic test of data-driven.
Go out as shown in Figure 2 for general driving unit flowchart, comprise the steps:
Step 201 is obtained function address according to function name, is designated as FuncAddr.According to different operating system, different language, different compilers realize that this step has diverse ways.The API of some operating system as vxworks itself just provides, some operating system such as windows directly do not provide API, but can obtain function address by .exe or the .map file of analyzing the compiler generation.Because this step is not a key content of the present invention, so no longer describe in detail.
Step 202 is searched buffer cell, obtains the tested function parameter that presets, the value of global variable.
Among the present invention, buffer cell provides following API to carry out the setting of buffer zone and to read:
Read the function parameter value in the buffer cell;
Function parameter value in the buffer cell is set;
Read the global variable value in the buffer zone;
Global variable value in the buffer zone is set;
Step 203 is obtained tested function parameters and global variable information from the buffering unit, and its global variable value is set, and will go into ginseng and be pressed into the program current stack according to certain rule.
Global variable is the same as with function globak symbol, is assigned the address when compiling, reads its prevalue from buffer zone, and the value that this global variable is set is a prevalue.
Tested function parameters is set visits the storehouse of this tested function, the parameter value when carrying out so that it to be set.Stack accessing is by top-of-stack pointer ESP visit, and parameter is stacked according to the about definite sequence of tested function calls, and safeguards top-of-stack pointer simultaneously, guarantees the correctness of storehouse.The detail and the compiler in this step are closely related, with byte-aligned and different variation of function call agreement.
Below with byte alignment, _ _ the cdecl method of calling is that example describes step 203 in detail:
1. for n parameter of tested function, to first parameter, be done as follows successively from n parameter:
(1) obtains the buffer zone parabuffer of this parameter, obtain the shared byte number size of this parameter;
(2), then that the address of the data data block of parabuffer is stacked if this parameter is a pointer.The stack manipulation of this parameter is finished, and gets back to 1, carries out the stack manipulation of next parameter;
(3) if the parameter size is not 4 integral multiple, the integral multiple of polishing to 4: size=size+ (4-size%4) then;
(4) execution command sub esp, size is about to top-of-stack pointer and reduces size;
(5) because the push instruction can only be to data manipulation in 4 bytes, consider big byte parameter, we adopt the mode that is similar to memcpy, the whole code stream of this parameter is stacked, in order to prevent that the memcpy function call from exerting an influence to storehouse, directly use assembly language to substitute the memcpy function and realize memory copying.
(6) the shared total bytes of all parameters of tested function that adds up is designated as AllSize;
2. for each global variable in the tested function, do following operation successively:
(1) obtains the buffer zone of this global variable, be designated as pGlovar;
(2) obtain the address of this global variable, be designated as GlovarAdd;
(3) if this global variable is a pointer, then the address is copied among the GlovarAdd, otherwise the code stream of global variable is copied among the GlovarAdd.
Step 204 is carried out this tested function, and code is _ _ asm call FuncAddr.
Step 205 is obtained global variable, is gone out ginseng, function return value, deposits buffer zone in, and recovers the function storehouse;
The following describes the detailed process of step 205:
1. for the global variable of tested function, be done as follows successively:
(1) if this global variable is a pointer, deposited the result after carrying out at this moment in the data block of this global variable buffer zone, need not other operations, skip this global variable;
(2) if this global variable is not a pointer, need obtain the value of global variable, deposit back in the buffer zone.
2. for the value that goes out ginseng, obviously, having only parameter is under the situation of pointer, and this parameter could be as going out to join, and in the case, has deposited the result after the execution of this parameter in the data block of the buffer zone of this parameter.
3. the step of obtaining function return value is as follows:
(1) obtains the buffer zone of tested function return value, be designated as reBuffer;
(2) obtain the address of register eax: _ _ asm mov retval, eax
(3) if function return value is a pointer, then the value in the eax is deposited in the data block of reBuffer;
(4), directly should value take out and deposit buffering in and get final product if the shared byte number of function return value less than 4 bytes, has at this moment been deposited the value of rreturn value in the register eax;
(5) if the shared byte number of function return value greater than 4 bytes, at this moment deposits in the register eax is the address of function return value, need deposit the taking-up of the value this address in buffer zone;
4. recovery function address
Use the shared total bytes AllSize of all parameters of tested function of record in the step 203 to adjust storehouse, pseudo-code is: _ _ asm add esp, AllSize.
With the INTEL processor, the C language illustrates in the above description, does not represent the restriction to range of application of the present invention.
By the introduction of above modular structure figure and general driving function flowchart, main thought of the present invention has been set forth clear.Using a general driving function to substitute a large amount of driving functions is fleshes and bloods of the present invention, and the present invention has multiple different scheme when realizing, related herein specific implementation is just wherein a kind of.
Above content be in conjunction with concrete preferred implementation to further describing that the present invention did, can not assert that concrete enforcement of the present invention is confined to these explanations.For the general technical staff of the technical field of the invention, without departing from the inventive concept of the premise, can also make some simple deduction or replace, all should be considered as belonging to protection scope of the present invention.

Claims (6)

1. a unit test system is characterized in that, described system comprises: unit under test (105), buffer cell (102), general driving unit (101), unit of testing and controlling (106), information extraction unit (103), symbol table unit (104); Described information extraction unit (103) is input with unit under test (105), is used to extract the information of unit under test (105); Described unit of testing and controlling (106) is used for the information of the unit under test (105) of recalls information extraction unit (103) acquisition, and before test the information of calling is put into buffer cell (102), and controls described general driving unit (101) and test; General driving unit (101) obtains information from buffering unit (102), and puts into the test environment of setting, calls tested function, and output valve is put into buffer cell (102); Described unit of testing and controlling (106) also is used for extracting the judgement that output valve is finished test result from buffering unit (102); Described symbol table unit (104) is used for the information that packaging information extraction unit (103) extracts, and external interface is provided.
2. unit test system according to claim 1 is characterized in that, the information that described information extraction unit (103) is extracted from unit under test (105) comprises: data structure, function parameter, rreturn value, the global variable of unit under test (105).
3. unit test system according to claim 1 and 2 is characterized in that, described information extraction unit (103) is specifically extracted the information of unit under test (105) by the static scanning analysis mode.
4. a unit test method is characterized in that, described method comprises following treatment step:
1) information extraction unit (103) information extraction from unit under test (105), and deposit the information of extracting in symbol table unit (104);
2) unit of testing and controlling (106) is used for recalls information extraction unit (103) acquired information and deposits buffer cell (102) in;
3) general driving unit (101) obtain information from buffering unit (102), and put into the test environment of setting, call tested function, carry out test process, and deposit output valve in buffer cell (102);
4) unit of testing and controlling (106) also is used for extracting the judgement that output valve is finished test result from buffering unit (102).
5. unit test method according to claim 4 is characterized in that, the information of extracting in the described step 1) comprises: data structure, function parameter, rreturn value, the global variable of unit under test (105).
6. according to claim 4 or 5 described unit test methods, it is characterized in that information extraction unit in the described step 1) (103) adopts the static scanning analysis mode to extract the information of unit under test (105).
CNB2007100757420A 2007-08-14 2007-08-14 Unit test system and method thereof Active CN100511135C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2007100757420A CN100511135C (en) 2007-08-14 2007-08-14 Unit test system and method thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2007100757420A CN100511135C (en) 2007-08-14 2007-08-14 Unit test system and method thereof

Publications (2)

Publication Number Publication Date
CN101110024A CN101110024A (en) 2008-01-23
CN100511135C true CN100511135C (en) 2009-07-08

Family

ID=39042110

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2007100757420A Active CN100511135C (en) 2007-08-14 2007-08-14 Unit test system and method thereof

Country Status (1)

Country Link
CN (1) CN100511135C (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102096631B (en) * 2009-12-11 2013-09-25 华为技术有限公司 Interface testing method and device
CN103853532B (en) * 2012-11-29 2017-09-29 国际商业机器公司 Method and apparatus for function call
CN104731695B (en) * 2013-12-19 2018-11-09 广州凯乐软件技术有限公司 A kind of unit test system and method for supporting the input of table driving bottom
CN104731700B (en) * 2013-12-20 2018-11-09 广州凯乐软件技术有限公司 A kind of unit test system and method for supporting table driving local data
CN105808421A (en) * 2014-12-31 2016-07-27 中兴通讯股份有限公司 White box test realization method and test control end
CN106469048B (en) * 2015-08-18 2020-05-15 北京神州泰岳软件股份有限公司 Method and device for calling content in attribute configuration file
CN106547684A (en) * 2015-09-22 2017-03-29 腾讯科技(深圳)有限公司 A kind of method of testing of application program, test device and mobile terminal
CN109299003A (en) * 2018-08-31 2019-02-01 苏州洞察云信息技术有限公司 A kind of full-automatic testing case driving generation system towards complex software
CN110502439B (en) * 2019-08-07 2024-01-12 Oppo广东移动通信有限公司 Debugging method, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN101110024A (en) 2008-01-23

Similar Documents

Publication Publication Date Title
CN100511135C (en) Unit test system and method thereof
CN101110055B (en) Device for implementing general use pile function in unit test and implementing method thereof
CN105550296B (en) A kind of data lead-in method based on spark-SQL big data processing platforms
Dunn Software defect removal
Lindbom et al. Perl-speaks-NONMEM (PsN)—a Perl module for NONMEM related programming
CN102541521B (en) Automatic operating instruction generating device based on structured query language and method
CN107967316A (en) A kind of method of data synchronization, equipment and computer-readable recording medium
CN107291480A (en) A kind of function calling method and device
CN102193811B (en) Compiling device for eliminating memory access conflict and realizing method thereof
CN103942099B (en) Executing tasks parallelly method and device based on Hive
CN1248116C (en) General purpose testing arrangement for embedded module and subsystem based on host machine platform
CN102033948A (en) Method and device for updating data
CN105022646B (en) A kind of remote-code-update method and apparatus of data lossless
CN109145055A (en) A kind of method of data synchronization and system based on Flink
Buinevich et al. Method and prototype of utility for partial recovering source code for low-level and medium-level vulnerability search
CN100428184C (en) Command simulation analytic system with automatic driving function and realizing method thereof
CN110109671A (en) A kind of webpack label sizes pattern conversion method and device
US10191725B2 (en) Rearrangeable code optimization modules
CN113360157A (en) Program compiling method, device and computer readable medium
CN103793653A (en) Program dependence relationship analysis method and system based on tree optimization
CN1165844C (en) Method for determining software module testing information of digital equipment
CN101446898A (en) Method for supporting large scale parallel distributed computation through functional programming model
CN1219254C (en) IC card hardware simulator based on FPGA-51 kernel
CN103116495B (en) Based on automatic storage method and the device of the single-chip microcomputer register value of IDE
Skjellum The multicomputer toolbox: Current and future directions

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
ASS Succession or assignment of patent right

Owner name: STATE GRID SHANGHAI ELECTRIC POWER COMPANY

Free format text: FORMER OWNER: ZTE CORPORATION

Effective date: 20141224

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 518057 SHENZHEN, GUANGDONG PROVINCE TO: 200122 PUDONG NEW AREA, SHANGHAI

TR01 Transfer of patent right

Effective date of registration: 20141224

Address after: 200122 Shanghai City, Pudong New Area source deep road, No. 1122

Patentee after: State Grid Shanghai Municipal Electric Power Company

Address before: 518057 Nanshan District science and Technology Park, Guangdong, South Road, ZTE building, science and Technology Park

Patentee before: ZTE Corporation