CN105912464B - A kind of unit test method and device - Google Patents

A kind of unit test method and device Download PDF

Info

Publication number
CN105912464B
CN105912464B CN201610207623.5A CN201610207623A CN105912464B CN 105912464 B CN105912464 B CN 105912464B CN 201610207623 A CN201610207623 A CN 201610207623A CN 105912464 B CN105912464 B CN 105912464B
Authority
CN
China
Prior art keywords
unit
project
test
code
stage
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
CN201610207623.5A
Other languages
Chinese (zh)
Other versions
CN105912464A (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.)
Guangzhou Pinwei Software Co Ltd
Original Assignee
Guangzhou Pinwei Software 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 Guangzhou Pinwei Software Co Ltd filed Critical Guangzhou Pinwei Software Co Ltd
Priority to CN201610207623.5A priority Critical patent/CN105912464B/en
Publication of CN105912464A publication Critical patent/CN105912464A/en
Application granted granted Critical
Publication of CN105912464B publication Critical patent/CN105912464B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention discloses a kind of unit test methods, including obtain each sub-project development plan table in whole project, and normalization project table is generated according to pre-determined model;According to above-mentioned normalization project table, the unit for meeting preassigned is identified;The unit testing environment is generated according to pre-defined rule, completes test.The embodiment of the present invention can improve unit testing efficiency, reduce the cost of unit testing.

Description

A kind of unit test method and device
Technical field
The present invention relates to software testing technologies, especially propose a kind of unit test method and device.
Background technology
Unit testing is necessary link in large program exploitation, is surveyed to each component units of global procedures Examination, to detect whether each unit correctly realizes its scheduled function.Unit testing at present is mainly real according to each unit Existing function, test case is write for unit under test and the method for building test environment is realized.The problem of this method maximum exists In test code operation amount is big, each unit will individually write a large amount of test case and build test environment, expends big The manpower of amount and time.Particularly with large software, the workload for testing code is even more than the size of code of function code, and The time for building test environment accounts for the 40% even more of entire development time.
Invention content
For overcome the deficiencies in the prior art, the present invention is technical problems to be solved, provides a kind of unit test method And device, the overall efficiency of unit testing is effectively raised, the workload for writing test code is reduced, saves unit survey The time of examination.
To solve the above problems, the technical solution adopted in the present invention is as follows:
A kind of unit test method, includes the following steps:
Obtain each sub-project information table in whole project;
Normalization Project Information Table is generated according to each sub-project information table in the whole project;
According to the normalization Project Information Table, the unit for meeting preassigned is identified;
By pre-defined rule generate described in meet preassigned unit test environment;
The test environment is called, the unit testing of the unit of preassigned is met described in completion.
The normalization Project Information Table includes the normalization project information of each sub-project, wherein each sub-project is returned One change project information includes project process session information, logic upstream unit information, logic downstream unit information, project process The time point information in each stage in stage.
The project process stage includes newly-built stage, demand stage, waiting stage, development phase, test phase and It reaches the standard grade the stage.
The normalization Project Information Table is supported iterative developing or waterfall type exploitation or iterative is mixed out with waterfall type The sub-project information table of hair.
The unit for meeting preassigned refers in normalizing Project Information Table, in the logic function of the unit It is completed before downstream units test phase time started expected from the unit in upstream units and logic function respectively The unit testing of unit.
It is described to generate test environment by pre-defined rule, including execute following steps:
According to the normalization project information of the unit for meeting preassigned, the upstream units in its logic function are read And downstream units code;
According to the upstream units of the reading and downstream units code, respective test module connection code is generated;
The upstream units and its exciting test block code, generation unit is called to encourage module;
Call the downstream units and its result detection module code, generation unit result detection module;
Code, element excitation module, unit result detection module generation unit test wrapper are connected according to the test module Border.
A kind of unit testing device, which is characterized in that including:
Retrieval unit, for obtaining each sub-project development plan table in whole project;
Project table generation unit, for generating above-mentioned normalization project table;
Detection unit goes out to meet the unit of preassigned for identification;
Test environment generation unit, for generating said units test environment;
Test execution unit completes unit testing for calling the test environment.
The test environment generation unit further includes, and tests code generating unit, for according to above-mentioned selected upstream and Downstream units generate interface code.
Compared with prior art, the beneficial effects of the present invention are:
1, by borrowing the upstream for the unit for meeting preassigned and the test environment of downstream units, unit is effectively reduced The workload that test environment is built.
2, by using normalization project table, while waterfall type software development and iterative software development model being supported, The unit discrimination for meeting preassigned is improved, the workload of unit testing environmental structure is effectively reduced.
3, by testing code reuse, testing efficiency is effectively increased.
Above description is only the general introduction of technical solution of the present invention, in order to better understand the technical means of the present invention, And can be implemented in accordance with the contents of the specification, and in order to allow the above and other objects, features and advantages of the present invention can It is clearer and more comprehensible, it is special below to lift preferred embodiment, and coordinate attached drawing, detailed description are as follows.
Description of the drawings
Fig. 1 is the structure chart of general cell test environment.
Fig. 2 is to build test environment schematic diagram using upstream and downstream unit.
Fig. 3 is unit test method flow chart of the embodiment of the present invention.
Fig. 4 is that the exploitation of waterfall type of the embodiment of the present invention is aligned principle with iterative developing as schemed.
Fig. 5 is the flow chart of generation unit test environment of the embodiment of the present invention.
Fig. 6 is unit testing environmental structure figure.
Fig. 7 is a kind of structural schematic diagram of unit testing device provided in an embodiment of the present invention.
Specific implementation mode
Detailed description of the present invention specific implementation mode below in conjunction with the accompanying drawings.
In general large-scale software development project, whole software can be divided into several function modules, Mei Gegong according to function Energy module can be divided into several unit modules according to the function to be completed again.Usually the unit testing is aiming at these The test of unit module.Whole software can be completed by multiple project team joint developments, and development progress differs between different units It causes, the rear completion that some is first completed.So there are certain software units, these units carry out after its code development Before unit testing, the upstream and downstream unit in logic function, which has been developed, finishes and completes respective unit testing.At this time may be used With using in the cellular logic upstream and downstream unit and its test environment build and be suitble to the unit testing environment of the unit, from And the workload of unit testing environmental structure is reduced, improve unit testing efficiency.
Fig. 1 is the structure chart of general cell test environment, and wherein excited modes root tuber generates excited data hair according to test case Give unit under test;As a result the correctness of the result of detection module detection unit under test output.It is tested that exciting unit simulates this The all possible input data situation of unit;Detection module detection is tested single in the excitation various input datas of module Whether the output data of member meets the output data in it is expected, to judge whether tested module has design mistake.
Fig. 2 is to build test environment schematic diagram using upstream and downstream unit, complete by the test environment for borrowing upstream and downstream unit At building for unit testing environment.
Fig. 3 is unit test method flow chart of the embodiment of the present invention.The flow originates in step 301.Then in step 302 Obtain each sub-project information table in whole project.Sub-project information table is related to the development scheme of project, the exploitation of general data Mode is divided into two kinds of waterfall type software development mode and iterative software development mode.Disparity items selects to close according to respective demand The development scheme of oneself is fitted to work, wherein waterfall type development scheme is more iterative relatively sharp on time schedule node, So generally selecting on the basis of waterfall type development scheme, converting iterative developing mode to by certain technological means has With the time schedule node as waterfall type development scheme normalization table is realized to the development plan of unified whole project Record project status.
Normalization Project Information Table is generated in step 303, brief description is done to normalization Project Information Table at this, is generated Normalization table is the development scheme because different, and project development pattern is different, and time planning mode is also different, is opened in different Under hair pattern, it is difficult to unified clear functional requirement and the development progress of each function module, so needing through unified normalization Table realizes item-function and progress record under different mode exploitation.Concrete example illustrates how waterfall type developing mould below The development progress of formula and iterative developing pattern is unified by normalizing table, and citing herein, which only describes, realizes normalization table A kind of implementation method of lattice does not form other methods and limits.A kind of stage iterative project is introduced herein to waterfall The stage of the method for formula project stage snap, waterfall type project mainly has:Newly-built stage, demand stage, waiting stage, exploitation rank Section, has been reached the standard grade the stage at test phase;In order to be aligned, the demand of iterative developing is also provided with newly-built stage, demand stage, row Stage phase, test phase, has reached the standard grade these stages in stage at the development phase, their alignment relation is as shown in Figure 4.By upper The method for being segmented iterative developing is stated, iterative developing is developed with waterfall type on the project stage and is aligned.Normalize table According to each sub-project stage of alignment, the state of each unit, the logical relation of progress and peripheral unit and arrangement of time are recorded Plan, generates the table.
The unit for meeting preassigned is identified in step 304.The preassigned refers to meeting preset structure The standard of test environment, i.e., described to meet the unit of preassigned refer to the logic of the unit in normalizing Project Information Table Downstream units in upstream units and logic function functionally complete the separate unit testing time in unit entrance Before the timing node of test phase.
In step 305 according to the above-mentioned unit identified, the unit testing environment is generated, completes test.
Flow ends at step 306.
Fig. 5 is shown in step 305 according to the flow chart of pre-defined rule generation unit test environment.The flow originates in step 501.Then in step 502 according to the normalization project information of the unit for meeting preassigned, reading meets preassigned Unit logic function on upstream units and downstream units code.In step 503, upstream and the downstream units of reading are scanned Code, read module input/output interface define partial content, generate test module and connect code.It is called in step 504 described Upstream units and its exciting test block code generate the element excitation module of unit under test.The downstream is called in step 505 Unit and its result detection module code, generation unit result detection module;Mould is connected according to the test module in step 506 Block, element excitation module, unit result detection module generation unit test environment.Step 507 terminates.
Fig. 6 is unit testing environmental structure figure described in Fig. 5, the upstream units of unit under test and its exciting test module generation Code, generates the element excitation module of unit under test.The downstream units and its result detection module of unit under test, generation unit result Detection module.Test module link block connects unit under test and element excitation module and result detection module, generates Test environment.
Fig. 7 is a kind of structural schematic diagram of unit testing device provided in an embodiment of the present invention.Including retrieval unit 701, Project table generation unit 702, detection unit 703, test environment generation unit 704, test execution unit 705.
Wherein, retrieval unit, for obtaining each sub-project development plan table in whole project;Project table generation unit, For generating above-mentioned normalization project table;Detection unit goes out to meet the unit of preassigned for identification;Test environment generates Unit, for generating said units test environment;Test execution unit completes unit testing for calling the test environment.
The test environment generation unit further includes, and tests code generating unit, for according to above-mentioned selected upstream and Downstream units generate interface code.
Further, above-mentioned interface code can automatically be write by test code generating unit.Specifically, foot can be passed through This program scanning upstream and downstream module read it and are defined about input and output, and automatically generate to have by script and input, is defeated Go out the encirclement module of definition.
Further, automatically generating for test environment can also be realized by test environment generation unit.For in selection Upstream and the downstream units for stating unit to be tested according to the interface code of above-mentioned generation, and call existing test code, generate Unit testing environment.
Although specific embodiments of the present invention have been described above, those skilled in the art should manage Solution, these are merely examples, and many changes and modifications may be made, without departing from the principle of the present invention And essence.The scope of the present invention is only by the claims limited.

Claims (5)

1. a kind of unit test method, which is characterized in that include the following steps:
Obtain each sub-project information table in whole project;
Normalization Project Information Table is generated according to each sub-project information table in the whole project;
According to the normalization Project Information Table, the unit for meeting preassigned is identified;
By pre-defined rule generate described in meet preassigned unit test environment;
The test environment is called, the unit testing of the unit of preassigned is met described in completion;
It is described to generate test environment by pre-defined rule, further include executing following steps:
According to the normalization project information of the unit for meeting preassigned, the logic work(for the unit for meeting preassigned is read Upstream units on energy and downstream units code;
According to the upstream units of the reading and downstream units code, generates test module and connect code;
The upstream units and its exciting test block code, generation unit is called to encourage module;
Call the downstream units and its result detection module code, generation unit result detection module;
Code, element excitation module, unit result detection module generation unit test environment are connected according to the test module.
2. unit test method as described in claim 1, it is characterised in that:The normalization Project Information Table includes each subitem Purpose normalizes project information, wherein the normalization project information of each sub-project includes project process session information, logic Upstream units information, logic downstream unit information, in the project process stage each stage time point information.
3. unit test method as claimed in claim 2, it is characterised in that:The project process stage includes the newly-built stage, needs It asks stage, waiting stage, development phase, test phase and has reached the standard grade the stage.
4. unit test method as described in claim 1, it is characterised in that:The normalization Project Information Table is supported iterative Exploitation or waterfall type exploitation or iterative and waterfall type mixed developing sub-project information table.
5. unit test method as described in claim 1, it is characterised in that:The unit for meeting preassigned refers to returning One changes in Project Information Table, and the time that respective unit testing is completed in upstream and downstream units in the logic function of the unit is early In the unit testing time point of the unit.
CN201610207623.5A 2016-04-01 2016-04-01 A kind of unit test method and device Active CN105912464B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610207623.5A CN105912464B (en) 2016-04-01 2016-04-01 A kind of unit test method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610207623.5A CN105912464B (en) 2016-04-01 2016-04-01 A kind of unit test method and device

Publications (2)

Publication Number Publication Date
CN105912464A CN105912464A (en) 2016-08-31
CN105912464B true CN105912464B (en) 2018-08-24

Family

ID=56745578

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610207623.5A Active CN105912464B (en) 2016-04-01 2016-04-01 A kind of unit test method and device

Country Status (1)

Country Link
CN (1) CN105912464B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970648A (en) * 2013-01-30 2014-08-06 百度国际科技(深圳)有限公司 Test method and system of installation package
CN104618955A (en) * 2015-03-04 2015-05-13 上海华东电信研究院 Mobile communication terminal consistency test item set generating method and system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB0206761D0 (en) * 2002-03-22 2002-05-01 Object Media Ltd Software testing

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970648A (en) * 2013-01-30 2014-08-06 百度国际科技(深圳)有限公司 Test method and system of installation package
CN104618955A (en) * 2015-03-04 2015-05-13 上海华东电信研究院 Mobile communication terminal consistency test item set generating method and system

Also Published As

Publication number Publication date
CN105912464A (en) 2016-08-31

Similar Documents

Publication Publication Date Title
Linzhang et al. Generating test cases from UML activity diagram based on gray-box method
CN106528424B (en) Test method and test platform based on background system service or interface
CN102819492B (en) Keyword driven automatic testing frame on basis of Android
CN105022691B (en) A kind of increasingly automated method for testing software based on uml diagram
CN110321281A (en) Web test platform and test method based on mixing automated test frame
US20090019427A1 (en) Method and Apparatus for Providing Requirement Driven Static Analysis of Test Coverage for Web-Based, Distributed Processes
CN105095059B (en) A kind of method and apparatus of automatic test
US7895575B2 (en) Apparatus and method for generating test driver
CN107203473A (en) The automatization test system and method for automatic expansion interface test case
CN105760296B (en) Automatic test control method, device and terminal
CN111950212A (en) Efficient multi-mode verification platform and method
JP2007012003A (en) System for providing development environment of feature-oriented software product line
CN111428431A (en) Method and system for supporting automatic test and recording of EDA (electronic design automation) software
CN108415830A (en) A kind of generation method and device of software test case
CN104750606B (en) A kind of automated testing method based on reflection
CN107239392A (en) A kind of method of testing, device and terminal
CN105677306A (en) Automation script compiling method and device
CN106598834A (en) UI (User Interface) testing method and device
CN107608894A (en) Software testing generation method, system and storage medium based on dynamic model
CN105279092A (en) Software testing method and apparatus
CN113127368A (en) Method, system and medium for generating assembly line
CN102135939A (en) Test case operation dispatching device and method
CN101604290A (en) A kind of background module method of testing and background module test macro
CN105320510B (en) A kind of method and device of automatic tracing data relationship
CN105912464B (en) A kind of unit test method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20180117

Address after: 510370 Guangzhou City, Guangzhou, Guangdong, Fangcun Avenue, one of the 314 self compiled

Applicant after: Guangzhou Pinwei Software Co., Ltd.

Address before: No. 20, Liwan District Huahai street, Guangzhou, Guangdong Province

Applicant before: GUANGZHOU VIP NETWORK TECHNOLOGY CO., LTD.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant