CN1273897C - Automatic approach for unit testing - Google Patents
Automatic approach for unit testing Download PDFInfo
- Publication number
- CN1273897C CN1273897C CN 02146712 CN02146712A CN1273897C CN 1273897 C CN1273897 C CN 1273897C CN 02146712 CN02146712 CN 02146712 CN 02146712 A CN02146712 A CN 02146712A CN 1273897 C CN1273897 C CN 1273897C
- Authority
- CN
- China
- Prior art keywords
- unit testing
- test
- data
- file
- script file
- 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
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Abstract
The present invention discloses an automatic method for unit testing, which controls tested program units through script files and has the steps that the tested script files control unit testing auxiliary modules; unit testing auxiliary modules control tested program units; a script interpreter carries out interpretive execution on program codes in the tested script files and writes set data in data exchanging files according to the behavior of the program codes; the tested program units call functional functions in the unit testing auxiliary modules; the functional functions in the unit testing auxiliary modules read set data in the data exchanging files; redefining key words and functional executing results are controlled by setting the data; the functional functions in the unit testing auxiliary modules control tested program units through the redefined key words or the functional functions, and therefore, a simple and automatic unit testing process is provided to realize the aims that executing efficiency of unit testing is improved, a regression test is convenient, and the unit testing cost is reduced.
Description
Technical field
The present invention relates to the unit testing field, particularly a kind of automated unit test method.
Background technology
Unit testing is to concentrate each program element of being realized by source code is tested, and checks whether each program module has correctly realized the function of regulation.The branch that each control structure is checked in unit testing is to guarantee to cover fully the bug check with maximum possible.
At present, generally finish unit testing by the method that in program code, increases test code, writes a large amount of pile functions and driving function.The problem of this method maximum is exactly need to revise a large amount of program codes, and test process can not robotization, and the execution efficient of test is very low.
Unit testing is the mistake for discovery procedure as much as possible, after the discovery mistake, in order to correct mistakes, need make amendment to program code.When program code was modified, some aspect of application configuration (as document or data) also can be modified.Regression test is that the program of revising is tested one time more again, to guarantee that it is correct revising, guarantees that simultaneously the modification of being made can not bring unpredictable behavior or new mistake.
Because test process can not carry out automatically, therefore will be very loaded down with trivial details for the regression test process behind the bug patch.The correct test case of test must be tested one time more again, be correct to guarantee to revise, and do not introduce other mistake.
For some situations that is difficult to simulate, when failing, because can't carry out these codes at all, so its corresponding code process branch just is difficult to cover when unit testing as Memory Allocation.
Test is finished, and in the time of released version, also needs from program code a large amount of test code of deletion, and this process is often complicated and very easily make mistakes.
In sum, the robotization of test process will become the direction of unit testing development.
Summary of the invention
In view of this, the object of the present invention is to provide a kind of automated unit test method, realize the robotization of unit testing process, improve the efficient of unit testing.
In order to achieve the above object, the invention provides a kind of automated unit test method, it is characterized in that: be provided for the test procedure unit test script file, be used for to test script file make an explanation and the execution script interpreter, with the unit testing supplementary module of driving function and pile function encapsulation, the method includes the steps of:
A, script interpreter explain the program code of carrying out in the test script file, write in data interchange file according to the execution result of program code data are set;
Power function in B, the tested program element call unit test supplementary module, in the power function reading of data swap file in the unit testing supplementary module data are set, by the key word (as: if statement) that Data Control redefines and the execution result of function are set.
Preferably, this method further comprises: the time that test script file comes into force by data in the time-delay control setting data interchange file.
Test script file can be quoted the function in the dynamic link libraries.Test script file and tested program element carry out information interaction, according to the dynamic link libraries function that test script file calls, select the program code branch of test script file present procedure code back.
The present invention is packaged into a general independently unit testing supplementary module by testing with pile function and driving function, and by test script file control pile function and driving function, thereby control tested program element.Further, for the covering (as: Memory Allocation failure) of some branches that are difficult to simulate, can enter different operational schemees and realize by controlling tested program element.Improved the execution efficient of unit testing, realized the robotization of unit testing process, made the unit testing simple general-purpose; During regression test, only need to use this test script file to test again and get final product, simplified regression test greatly, reduced the cost of unit testing.Whether the test script file at same unit testing can be reused, no matter tested by same tester.
Description of drawings
Fig. 1 shows the synoptic diagram of controlling tested program element according to test script file of the present invention.
Embodiment
In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention is described in further detail below in conjunction with accompanying drawing.
Fig. 1 shows the synoptic diagram of controlling tested program element according to test script file of the present invention, as shown in Figure 1:
When carrying out unit testing, test macro mainly is divided into following several sections: test script file 101, script interpreter 102, data interchange file 103, unit testing supplementary module 105 and tested program element 104.Wherein unit testing supplementary module 105 and tested program element 104 have been formed tested system 106.The present invention is that driving function and the pile function that will test are packaged into a general independently unit module, and promptly the unit testing supplementary module 105.
Power function in the tested program element 104 call units test supplementary module 105, in the power function reading of data swap file 103 in the unit testing supplementary module 105 data are set, by the key word that Data Control redefines and the execution result of function are set, thereby by the tested program element 104 of unit testing supplementary module 105 controls.
The behavior of the tested program element 104 of unit testing supplementary module 105 controls mainly realizes by redefining all kinds of main key words and function.Redefine which key word and which function and decide according to the test needs fully, can expand arbitrarily.
For example, need to redefine the if statement in the test process, carry out the purpose of branch, so, can carry out following redefining if statement (key word) to reach control if statement:
#define?if(x)if(IfForUT(_FILE_,_LINE_,bool(x)))
Wherein, IfForUT is a self-defining function, and its functional form is as follows:
bool?IfForUT(LPCSTR?lpszFileName,int?nLine,bool?bCondition);
Just can read from data interchange file in the IfForUT function data are set, if the nLine line statement that the user is provided with in the file of lpszFileName indication will return false, then IfForUT directly returns false.If be not provided with, the IfForUT function returns the value of bCondition, and the if statement is carried out by its original behavior.
For another example, wish simulation new operation failure in the test process, but the tested program element of desired modifications not so, can redefine the new operational character:
#define?new?DEBUG_NEW
#define?DEBUG_NEW?new(THIS_FILE,_LINE_)
void*operator?new(size_t?nSize,LPCSTR?lpszFileName,int?nLine)
In self-defining new operation, just can from data interchange file, read data are set, judge according to user's being provided with in script file the capable internal memory application of nLine in the file of lpszFileName indication operates whether return failure.So just reached the situation of the Memory Allocation failure that may simulate hardly under the simulating actual conditions, and the code process branch after the Memory Allocation failure just can test successfully also.
Illustrate the situation that redefines function again.
Wish that in test process the execution result (rreturn value) of function d bcmd that DBLibrary is provided controls, can be defined as follows grand so:
#define?dbcmd(dbproc,cmdstring)dbcmdForUT(_FILE_,_LINE_,dbproc,cmdstring)
Defined function dbcmdForUT again
In the dbcmdForUT function, the explanation of similar previous exemplary, any value should be returned in the time of can determining in the lpszFileName indication file the capable dbcmd of the calling function of nLine according to user's being provided with in script file.
This mode can realize full automation for the test of distinct program branch in the unit testing, can make test cover some program branches that are difficult to simulate.And the user can be provided with same statement at different time and return different execution results, so just can control tested program element 104 and enter different operational schemees.Therefore, can in automatic testing process, finish the test of all branches.
Testing used script file 101 is can be reusable.After revising code, only the used script file 101 of test need be re-executed once, just can finish regression test, greatly improved unit testing efficient.
Whether unit testing supplementary module 105 compiles, loads fully and control by macro definition.Therefore, after unit testing finishes, only need remove grand, just can complete discharge unit testing supplementary module 105, can and not carry out any influence of generation after the unloading to the compiling of released version.
In a word, the above is preferred embodiment of the present invention only, is not to be used to limit protection scope of the present invention.
Claims (3)
1, a kind of automated unit test method, it is characterized in that: be provided for the test procedure unit test script file, be used for to test script file make an explanation and the execution script interpreter, with the unit testing supplementary module of driving function and pile function encapsulation, the method includes the steps of:
A, script interpreter explain the program code of carrying out in the test script file, write in data interchange file according to the execution result of program code data are set;
Power function in B, the tested program element call unit test supplementary module is provided with data in the power function reading of data swap file in the unit testing supplementary module, by the key word that Data Control redefines and the execution result of function are set.
2, automated unit test method as claimed in claim 1 is characterized in that, described test script file is by being provided with the time that data come into force in the time-delay control data swap file.
3, automated unit test method as claimed in claim 1, it is characterized in that, this method further comprises: described test script file and tested program element carry out information interaction, according to the dynamic link libraries function that test script file calls, select the program code branch of test script file present procedure code back.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 02146712 CN1273897C (en) | 2002-11-04 | 2002-11-04 | Automatic approach for unit testing |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 02146712 CN1273897C (en) | 2002-11-04 | 2002-11-04 | Automatic approach for unit testing |
Publications (2)
Publication Number | Publication Date |
---|---|
CN1499374A CN1499374A (en) | 2004-05-26 |
CN1273897C true CN1273897C (en) | 2006-09-06 |
Family
ID=34232849
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN 02146712 Expired - Fee Related CN1273897C (en) | 2002-11-04 | 2002-11-04 | Automatic approach for unit testing |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN1273897C (en) |
Families Citing this family (16)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100407162C (en) * | 2004-09-30 | 2008-07-30 | 中兴通讯股份有限公司 | Integrated software testing method with test flexibility |
CN100401264C (en) * | 2005-06-06 | 2008-07-09 | 华为技术有限公司 | Data-driven automatic testing system and method |
CN100401265C (en) * | 2005-06-06 | 2008-07-09 | 华为技术有限公司 | Keyword-driven automatic testing system and method |
DE102005036321A1 (en) * | 2005-07-29 | 2007-02-01 | Siemens Ag | Test scenarios generating method for e.g. computer tomography system, involves determining dependences between individual processing steps and/or classes of steps, and generating scenarios based on selection of steps, classes or rules |
CN100373326C (en) * | 2005-09-13 | 2008-03-05 | 华为技术有限公司 | Automation test system and method |
CN1952818B (en) * | 2005-10-22 | 2010-12-15 | 康佳集团股份有限公司 | Testing method of program unit with capability of checking test result automatically |
CN100370434C (en) * | 2005-11-01 | 2008-02-20 | 华为技术有限公司 | Method and system for realizing software automatic test |
CN100389391C (en) * | 2005-11-24 | 2008-05-21 | 北京中星微电子有限公司 | System and method for calling host software functions by using script and its compiler |
CN100452062C (en) * | 2006-01-13 | 2009-01-14 | 大同股份有限公司 | Method for testing hardware circuit block writen by hardware descriptive language |
CN100571167C (en) * | 2006-02-24 | 2009-12-16 | 国际商业机器公司 | The method and apparatus of the unit testing of Web service operation flow |
CN100363906C (en) * | 2006-02-28 | 2008-01-23 | 华为技术有限公司 | Method for testing software unit |
CN101098259B (en) * | 2006-06-30 | 2010-08-18 | 中兴通讯股份有限公司 | Automatized test method and system for implementing large data impact |
CN100451988C (en) * | 2006-11-14 | 2009-01-14 | 无敌科技(西安)有限公司 | Method and system for realizing unit test |
CN102375103B (en) * | 2010-08-27 | 2015-07-29 | 富泰华工业(深圳)有限公司 | Electronic product test device and method |
CN103593277A (en) * | 2012-08-15 | 2014-02-19 | 深圳市世纪光速信息技术有限公司 | Log processing method and system |
CN104050081B (en) * | 2014-06-09 | 2017-09-12 | 汉柏科技有限公司 | The method and system of the static built-in function of debugging |
-
2002
- 2002-11-04 CN CN 02146712 patent/CN1273897C/en not_active Expired - Fee Related
Also Published As
Publication number | Publication date |
---|---|
CN1499374A (en) | 2004-05-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN1273897C (en) | Automatic approach for unit testing | |
US6442660B1 (en) | Dynamic system relocation based on availability of system memory | |
US5170465A (en) | Incremental-scanning compiler for source-code development system | |
CN112084113B (en) | Configurable automatic test method and system based on embedded simulation verification software | |
CN101799763A (en) | Method, device and system for patching kernel on line | |
EP0665496A1 (en) | Method and apparatus for run-time error checking using dynamic patching | |
US20030212983A1 (en) | Method and system for modifying executable code to add additional functionality | |
US7284237B2 (en) | Testing flow control at test assertion level | |
US20050223360A1 (en) | System and method for providing a generic user interface testing framework | |
CN101334753B (en) | Unit test method and its device | |
CN105354045A (en) | Patch making method and apparatus and patch activation method and apparatus | |
US20050229161A1 (en) | Generic user interface testing framework with load-time libraries | |
CN115617687B (en) | Program instrumentation method, device, equipment and storage medium | |
US20050228644A1 (en) | Generic user interface testing framework with rules-based wizard | |
CN110069414B (en) | Regression testing method and system | |
CN114924737A (en) | Battery management system source code integration test method and device and electronic equipment | |
KR0125605B1 (en) | Method and device for verifying operation of machine language program | |
US7028294B2 (en) | Linking of applications into devices having overlays and shadow memories | |
CN109144849A (en) | A kind of embedded software adjusting, measuring method | |
EP0801348A1 (en) | Method of monitoring the operation of a computer | |
CN111984329B (en) | Boot software standardized generation and execution method and system | |
CN113886145A (en) | Program self-backup method based on-chip FLASH and without rewriting | |
CN112241268A (en) | Keil engineering compiling method, system and equipment | |
CN114035920A (en) | Method and device for symmetric loading and running of DSP (digital Signal processor) program | |
CN100458719C (en) | Method and system obtaining and compliling basic input and output system information |
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 | ||
C17 | Cessation of patent right | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20060906 Termination date: 20131104 |