CN100451988C - Method and system for realizing unit test - Google Patents

Method and system for realizing unit test Download PDF

Info

Publication number
CN100451988C
CN100451988C CNB2006101048978A CN200610104897A CN100451988C CN 100451988 C CN100451988 C CN 100451988C CN B2006101048978 A CNB2006101048978 A CN B2006101048978A CN 200610104897 A CN200610104897 A CN 200610104897A CN 100451988 C CN100451988 C CN 100451988C
Authority
CN
China
Prior art keywords
test
function
module
tested
result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB2006101048978A
Other languages
Chinese (zh)
Other versions
CN1987821A (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.)
Inventec Besta Xian Co Ltd
Original Assignee
Inventec Besta Xian Co Ltd
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 Inventec Besta Xian Co Ltd filed Critical Inventec Besta Xian Co Ltd
Priority to CNB2006101048978A priority Critical patent/CN100451988C/en
Publication of CN1987821A publication Critical patent/CN1987821A/en
Application granted granted Critical
Publication of CN100451988C publication Critical patent/CN100451988C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

This invention is an element testing system and method, especially a way which is used to record the information of the function and a function will be took out the developing environment to do element testing, the testing cover rate and testing report of the function will be produced according to the test of the function example, and this can be as the element testing system and method of the function quality relateence data. The technology scheme is that this method includes the process as follows: 1) recording the function information, storage testing example and the corresponding expect result of the testing function. 2) Uploading and initializing the recording testing function. 3) Reading out the storing example and expect result. 4) Detecting the reading example on sequence and obtaining the result. 5) Judging whether the testing finishes, if not, returning to 4), or going on 6). 6) Producing the cover rate of this detection, comparing the testing result with the excepted result, producing the testing report, outputting the testing cover rate and testing result.

Description

A kind of method and system that realize unit testing
Technical field
A kind of unit test system and method, especially a kind of mode of utilizing the record function information, one function is detached development environment carry out unit testing, the test coverage and the test report of this function being tested generation according to the test case (test case) of this function are as the unit test system and the method for the quality reference data of this function.
Background technology
Unit testing is the wherein a kind of of multiple test in the program design field.Normally for a unit in the test procedure, for example a classification (class), a function (function) etc. are tested by the programmer who is responsible for this unit.What tested is that whether its program code unit of writing is carried out according to the contemplated mode of programmer, meets expected result thereby produce.Unit testing is the very important ring of program design, and it plays a part problem report (bug report), tells that the there is wrong in our program code.Owing to after we finish or revise a unit, all need to carry out again unit testing, if program code also has the words of problem can continue to show.
Along with the function of software from strength to strength, the program code of software is also more and more tediously long, the bedbug (bug) that each module of software is produced when integrating is also more and more, therefore when integrating, to find out the also relative lifting of complexity of bug, if purely look for bug, often only can find this bug and more valuable information can't be provided in artificial mode.
For more valuable detecting information is provided, there is the programmer can write the program of unit testing, but the environment that can't leave its exploitation is done test, so that just in case the development environment when integrating in each unit of software is slightly different, in case the result who integrates is not as expection, still can't learn it is to integrate the influence that environment causes actually, or the interface of two unit (interface) is out of joint on data transfer, in this way the former, the so previous unit testing of doing has just lost meaning.
In addition, because the program of unit testing is arranged, the test case that will need unit testing so carries out unit testing.But can test case measure the program code of how many parts, and just the test coverage of unit is just present, does not also have better test mode.
Summary of the invention
The present invention is for solving the above-mentioned technical matters that exists in the background technology, and a kind of producible test coverage and the test report quality reference data as this function is provided, with the method and the system thereof of the unit testing that improves the software quality.
Technical solution of the present invention is: the present invention is a kind of method that realizes unit testing, and its special character is: this method may further comprise the steps:
1) at first write down function to be tested function information, the test case and the expected results corresponding with test case of function to be tested is stored in the test database;
2) function to be tested that then will be write down loads, and after loading with function initialization to be tested;
3) and then by the test case of reading function to be tested in the test database expected results corresponding with test case;
4) test case of reading is treated trial function in regular turn and test, to obtain the test result of test case;
5) judging whether test case has all been surveyed, otherwise return step 4), is then to proceed to step 6);
6) produce the test coverage of this test after all test is finished at all test cases, and, produce the test report of this test, export test coverage and test report by the expected results and the test result of compare test example correspondence.
The identical test case of program code that covers when above-mentioned steps 6) also including step 7) afterwards and will test only keeps one, remaining test case is deleted totally, the test result of testing the test report, test coverage and back remaining each test case of deletion that are produced is deposited in the database.
Above-mentioned steps 2) find in the initialized process of function to be tested in that function to be tested has the function of calling out other, then the passback value with called function replaces called function.
A kind of test macro of realizing the method for above-mentioned realization unit testing, its special character is: this system comprises test data library module 110, function Registering modules 120, function load-on module 130, function test module 140, comparison module 150 as a result, outcome record module 160, function Registering modules 120 inserts test data library module 110 and function load-on module 130 respectively, function load-on module 130 inserts function test module 140, function test module 140 inserts comparison module 150 as a result, comparison module 150 inserts outcome record module 160 as a result, outcome record module 160 inserts test data library module 110, and test data library module 110 inserts function load-on module 130.
The present invention utilizes the mode of record function information, one function is detached development environment carry out unit testing, test case according to this function is tested this function, and produce test coverage and test report, by test coverage and the test report that the present invention produced, can obtain the numerical value of a quantification, make software that a pointer on the quality be arranged, find to find out the bug in the software successively, to reach the effect that improves the software quality.
Description of drawings
Fig. 1 is the process flow diagram of method of testing of the present invention;
The system chart of Fig. 2 the present invention test;
The program code of first trial function in Fig. 3 embodiment of the invention;
Fig. 4 is that first trial function in the invention process is revised program code later;
Fig. 5 is the process of the execution the inventive method in the embodiment of the invention;
Fig. 6 is for testing the test coverage synoptic diagram that first trial function produces by first test case in the embodiment of the invention;
Fig. 7 is for testing the test report that first trial function produces by first test case in the embodiment of the invention;
Fig. 8 is the test coverage synoptic diagram that is produced by first trial function after first and second test case test modifications in the embodiment of the invention;
Fig. 9 is the test report that is produced by first trial function after first and second test case test modifications in the embodiment of the invention;
Figure 10 tests the test coverage synoptic diagram that second trial function produces for the embodiment of the invention by the 3rd and the 4th test case;
Figure 11 tests the test report that second trial function produces for the embodiment of the invention by the 3rd and the 4th test case;
Figure 12 is tested the test coverage synoptic diagram of second trial function by the 3rd test case for the embodiment of the invention;
Figure 13 is tested the test coverage synoptic diagram of second trial function by the 4th test case for the embodiment of the invention.
Embodiment
Referring to Fig. 1, concrete grammar step of the present invention is as follows:
1) at first write down function to be tested function information, the test case and the expected results corresponding with test case of function to be tested is stored in the test database;
2) function to be tested that then will be write down loads, and after loading with function initialization to be tested, find in this initialized process that function to be tested has the function of calling out other, then the passback value with called function replaces called function;
3) and then by the test case of reading function to be tested in the test database expected results corresponding with test case;
4) test case of reading is treated trial function in regular turn and test, to obtain the test result of test case;
5) judging whether test case has all been surveyed, otherwise return step 4), is then to proceed to step 6);
6) produce the test coverage of this test after all test is finished at all test cases, and, produce the test report of this test, export test coverage and test result by the expected results and the test result of compare test example correspondence.
7) the identical test case of program code that will cover in the time of will testing only keeps one, remaining test case is deleted totally, the test result of testing the test report, test coverage and back remaining each test case of deletion that are produced is deposited in the database.
Referring to Fig. 2, system of the present invention includes test data library module 110, function Registering modules 120, function load-on module 130, function test module 140, comparison module 150, outcome record module 160 as a result.Wherein test data library module 110 is responsible for storing test case, and the expected results of test case correspondence of the function information of the function to be tested that function Registering modules 120 are write down, the function to be tested that is recorded; Function Registering modules 120 is responsible for the function information such as definition of function name, passback value and each parameter of function to be tested are deposited in the test data library module 110; Function load-on module 130 is responsible for being read through the stored function information of function Registering modules 120 by test data library module 110, the function information that foundation is read is with in the function loading function test module 140 to be tested, and carry out initialization, as finding in the initialized process that function to be tested has the function of calling out other, then must replace called function with the passback value of called function, can guarantee so once to test only at a function, like this if problem can conclude it is the problem of this function own.Function test module 140 is responsible for reading the test case of the function to be tested that is stored in test data library module 110 and the expected results of test case correspondence, the test case of reading is tested function to be tested in regular turn, can produce the test result of test case correspondence, can after the whole tests of all test cases are finished, produce and export all test cases simultaneously and treat the test coverage that trial function is tested; Comparison module 150 is responsible for comparing the test result test case corresponding expected results corresponding with test result that is produced by function test module 140 as a result, produces test report, and with this test report output; Outcome record module 160 can be in explanation after a while.
When the use of user's desire is of the present invention, at first to be stored in the test database 110 via the function information of function Registering modules 120 with function to be tested, and the expected results that test case is corresponding with it also deposits in the test data library module 110, then begin to test, the function information that 130 meetings of function load-on module are read function to be tested by test data library module 110, obtain the program code of function to be tested according to the function information of reading, the program code of obtaining is carried in the function test module 140, and with function initialization to be tested, and then function test module 140 can be read the test case of the function to be tested that is stored in test data library module 110, and the expected results of test case correspondence, function test module 140 is after reading test case, the test case of reading can be tested function to be tested in regular turn, and the test result of generation test case correspondence, the program code that function test module 140 meetings simultaneously be tested the function to be tested that was covered with each test case is noted, after the whole tests of all test cases are finished, function test module 140 can produce test coverage and show according to the program code that each test case covered, then comparison module 150 can be relatively by the test result test case corresponding expected results corresponding with test result of function test module 140 generations as a result, and the generation test report also shows.
Below in conjunction with specific embodiment the present invention is described in further detail:
Referring to Fig. 3 to 9,310 realizations of first trial function are exported after finding out bigger variable by variable i of importing and j, the programmer uses the present invention to test, at first can import the function data-function name 3311 of first trial function 310, passback value 3312, parameter 1, parameter two 3314-carry out accreditation process 331 of the present invention, and other first test case with first trial function 310 " (5; 3)) " deposit in the database with first expected results " (5) ", then carry out test procedure 332 of the present invention, the present invention just can remove to obtain in the database first test case of first trial function 310 and first trial function is loaded and tests, after finishing, test produces test coverage 340, wherein the extrabold of first trial function, 310 fronts numeral is the trip preface code performed number of times that arrives when tested, and the number of times of front is that the test case of the trip preface code 341 these tests of expression of zero does not cover the trip preface code.After finishing, test produces test report 350, can know that by the test crash message 352 in the test report 350 first trial function 310 goes wrong when testing with first test case, can provide the programmer that first trial function 310 is made amendment.Simultaneously, by test coverage 340 as can be known the program code of first trial function 310 therefore need increase test case again and test the trip preface code not all through test.The programmer revises at first trial function and finishes after 320, second test case " (2; 7) " and second expected results " (7) " are deposited to database, first trial function 320 after once more modification being finished is tested, test coverage 360 demonstration first test cases and second test case that produce after test is finished are finished the whole tests of the program code of first trial function, the shown message 373 of test report is expressed as whole test cases all as expected results, thus, the quality of first trial function 310 just can be based oneself on to some extent, and the probability of makeing mistakes in the future significantly reduces.
Comparison module 150 can also be when function test module 140 be tested as a result among the present invention, test only keeping one in the identical test case of program code that covers, remaining test case is deleted totally, to only select one to go to carry out test in the identical test case of batch processing code as representative, can save the time of a large amount of execution test cases like this, outcome record module 160 is responsible for the test report with comparison module 150 generations as a result, the test coverage that function test module 140 produces deposits in the test data library module 110 with the test result that test obtains, so can be so that can provide follow-up regression test to use, so that test case has the effect of constantly reusing.Therefore as a result comparison module 150 after each test result that relatively produces and expected results corresponding to each test case by function test module 140, can be according to the test coverage of each test case, the identical test case of program code that covers is only kept one, remaining Delete All, then just can produce test report and show, and test report, test coverage that test is produced and will delete after the test result of remaining each test case deposit in the database.
Referring to Figure 10-13,410 realizations of second trial function are exported after finding out less variable by variable i of importing and j, after the programmer carries out accreditation process of the present invention, the 3rd test case " (2; 7) " and the 3rd expected results " (2) " with second trial function 410, the 4th test case " (4; 8) " deposits in the database with the 4th expected results " (4) ", second trial function 410 is tested, after finishing, test produces test coverage 420 and test report 430, and with the test coverage 420 and test report 430 and the 3rd that produce, the test result of the 4th test case deposits in the database, then, the test coverage 421 of the 3rd test case and the test coverage 422 of the 4th test case are identical, and test report 430 shows the deletion message 433 of the 3rd test case.

Claims (3)

1, a kind of method that realizes unit testing, it is characterized in that: this method may further comprise the steps:
1) at first the test case and the expected results corresponding with test case of the function information of function to be tested, function to be tested is stored in the test database;
2) function to be tested that then will be write down loads, and after loading with function initialization to be tested;
3) and then by the test case of reading function to be tested in the test database expected results corresponding with test case;
4) test case of reading is treated trial function in regular turn and test, to obtain the test result of test case;
5) judging whether test case has all been surveyed, otherwise return step 4), is then to proceed to step 6);
6) produce the test coverage of this test after all test is finished at all test cases, and, produce the test report of this test, export test coverage and test result by the expected results and the test result of compare test example correspondence;
7) the identical test case of program code that will cover in the time of will testing only keeps one, remaining test case is deleted totally, the test result of testing the test report, test coverage and back remaining each test case of deletion that are produced is deposited in the test database.
2, the method for realization unit testing according to claim 1, it is characterized in that: find in the initialized process of function to be tested described step 2) that function to be tested has the function of calling out other, then the passback value with called function replaces called function.
3, a kind of test macro of realizing the method for unit testing, it is characterized in that: this system comprises test data library module (110), function Registering modules (120), function load-on module (130), function test module (140), comparison module (150) as a result, outcome record module (160), described function Registering modules (120) inserts test data library module (110) and function load-on module (130) respectively, described function load-on module (130) inserts function test module (140), described function test module (140) inserts comparison module (150) as a result, described comparison module as a result (150) inserts outcome record module (160), described outcome record module (160) inserts test data library module (110), and described test data library module (110) inserts function load-on module (130); Wherein, test data library module (110) be responsible for to store test case, and the expected results of test case correspondence of the function information of the function to be tested that function Registering modules (120) write down, the function to be tested that is recorded; Function Registering modules (120) is responsible for the function information of function to be tested is deposited in the test data library module (110), and described function information comprises the definition of function name, passback value and each parameter; Function load-on module (130), be responsible for reading by the stored function information of function Registering modules (120) by test data library module (110), and function to be tested is loaded in the function test module (140), and carry out initialization according to the function information of reading; Function test module (140) is responsible for reading the test case of the function to be tested that is stored in test data library module (110) and the expected results of test case correspondence, and the test case of reading is tested function to be tested in regular turn; Comparison module (150) is responsible for comparing the test result test case corresponding expected results corresponding with test result that is produced by function test module (140) as a result, produces test report, and with this test report output; Outcome record module (160) is responsible for test coverage that the test report of comparison module (150) generation as a result, function test module (140) are produced and the test result that test obtains and is deposited in the test data library module (110).
CNB2006101048978A 2006-11-14 2006-11-14 Method and system for realizing unit test Expired - Fee Related CN100451988C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2006101048978A CN100451988C (en) 2006-11-14 2006-11-14 Method and system for realizing unit test

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2006101048978A CN100451988C (en) 2006-11-14 2006-11-14 Method and system for realizing unit test

Publications (2)

Publication Number Publication Date
CN1987821A CN1987821A (en) 2007-06-27
CN100451988C true CN100451988C (en) 2009-01-14

Family

ID=38184623

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2006101048978A Expired - Fee Related CN100451988C (en) 2006-11-14 2006-11-14 Method and system for realizing unit test

Country Status (1)

Country Link
CN (1) CN100451988C (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102567152A (en) * 2010-12-27 2012-07-11 佛山市顺德区顺达电脑厂有限公司 Automatic point-sorting system for on-line test device and method thereof
CN103364713B (en) * 2012-03-31 2016-04-20 中芯国际集成电路制造(上海)有限公司 The method of testing that electrical property failure is analyzed and device
CN103778052B (en) * 2012-10-17 2017-12-19 百度在线网络技术(北京)有限公司 A kind of method of testing and device of front end javascript codes
CN103309807B (en) * 2013-05-31 2016-03-02 中国联合网络通信集团有限公司 program testing method and platform
CN105204982A (en) * 2014-06-13 2015-12-30 腾讯科技(深圳)有限公司 Code testing method and code testing system
CN104182348B (en) * 2014-09-15 2017-04-12 北京国双科技有限公司 Software test method and device
CN104657270A (en) * 2015-02-28 2015-05-27 北京嘀嘀无限科技发展有限公司 Method and system for testing
CN105301480A (en) * 2015-11-19 2016-02-03 四川和芯微电子股份有限公司 Test method of SOC chip
CN105487982B (en) * 2015-12-22 2018-01-16 艾体威尔电子技术(北京)有限公司 API method of testings and system
CN107038110A (en) * 2016-02-03 2017-08-11 北京京东尚科信息技术有限公司 The method and system of white-box testing
CN106294130A (en) * 2016-07-28 2017-01-04 浪潮电子信息产业股份有限公司 A kind of unit test method and device
CN108572911A (en) * 2017-03-14 2018-09-25 北京京东尚科信息技术有限公司 Automate safety detecting method, device, electronic equipment and readable storage medium storing program for executing
EP3401849A1 (en) * 2017-05-09 2018-11-14 dSPACE digital signal processing and control engineering GmbH Determination of the maturity of a technical system
CN113360377B (en) * 2021-06-01 2023-11-07 北京京东振世信息技术有限公司 Test method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1994015289A1 (en) * 1992-12-23 1994-07-07 Taligent, Inc. Automated testing system
CN1499374A (en) * 2002-11-04 2004-05-26 华为技术有限公司 Automatic approach for unit testing
CN1641601A (en) * 2004-01-04 2005-07-20 华为技术有限公司 Software unit measuring method
CN1767453A (en) * 2004-10-31 2006-05-03 中兴通讯股份有限公司 Automatic test method and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1994015289A1 (en) * 1992-12-23 1994-07-07 Taligent, Inc. Automated testing system
CN1499374A (en) * 2002-11-04 2004-05-26 华为技术有限公司 Automatic approach for unit testing
CN1641601A (en) * 2004-01-04 2005-07-20 华为技术有限公司 Software unit measuring method
CN1767453A (en) * 2004-10-31 2006-05-03 中兴通讯股份有限公司 Automatic test method and system

Also Published As

Publication number Publication date
CN1987821A (en) 2007-06-27

Similar Documents

Publication Publication Date Title
CN100451988C (en) Method and system for realizing unit test
US7437692B2 (en) Memory debugger for system-on-a-chip designs
CN100468356C (en) Test case inheritance controlled via attributes
CN107861870A (en) Interface testing and test data generating method, device, terminal and storage medium
US9027002B2 (en) Method of converting source code and source code conversion program
CN109726105A (en) Test data building method, device, equipment and storage medium
CN109783346B (en) Keyword-driven automatic testing method and device and terminal equipment
US8140986B2 (en) Generating test scenarios using reusable triggers indicating graphical user interface (GUI) elements and actions
US20070061641A1 (en) Apparatus and method for generating test driver
US11361248B2 (en) Multi-stage machine learning-based chain diagnosis
CN112306855B (en) Interface automation test method, device, terminal and storage medium
CN105912460A (en) Software test method and system based on QTP
CN104750606B (en) A kind of automated testing method based on reflection
FR2921170A1 (en) METHOD FOR AUTOMATICALLY GENERATING PROGRAMS FOR TESTING AN OPERATING SOFTWARE OF AN ON-BOARD AIRCRAFT SYSTEM, AND DEVICE FOR IMPLEMENTING THE SAME
US20050229045A1 (en) Method and device for managing software error
CN111428431A (en) Method and system for supporting automatic test and recording of EDA (electronic design automation) software
CN110008119A (en) Report test method, device, computer equipment and storage medium
CN107622017B (en) Analysis method for universal automation software test
CN101937395B (en) Detected object program feature extraction method for vulnerability detection
Mainkar Expert Android Programming: Master skills to build enterprise grade Android applications
CN110069414A (en) Regression testing method and system
Cansell et al. Refinement: A constructive approach to formal software design for a secure e-voting interface
CN102929614A (en) Adjustable object program characteristic extracting method for detecting loophole
CN101662394A (en) Automated testing system and automated testing method
Ledru et al. Mastering combinatorial explosion with the tobias-2 test generator

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: 20090114

Termination date: 20091214