CN101145954A - Implementation method for piling class of communication function - Google Patents

Implementation method for piling class of communication function Download PDF

Info

Publication number
CN101145954A
CN101145954A CNA2007101114616A CN200710111461A CN101145954A CN 101145954 A CN101145954 A CN 101145954A CN A2007101114616 A CNA2007101114616 A CN A2007101114616A CN 200710111461 A CN200710111461 A CN 200710111461A CN 101145954 A CN101145954 A CN 101145954A
Authority
CN
China
Prior art keywords
class
piling
message
unit testing
communication layer
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.)
Pending
Application number
CNA2007101114616A
Other languages
Chinese (zh)
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.)
ZTE Corp
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 CNA2007101114616A priority Critical patent/CN101145954A/en
Publication of CN101145954A publication Critical patent/CN101145954A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention provides a communication function piling-like implementing method which comprises the following steps: step 1, providing a communication layer like in the coding process of a tested code, and compiling the piling like and tools like of the communication layer like; step 2, substituting the communication layer like by the piling like in the unit test operation environment; and step 3, calling the tools like during in unit test code, inputting the result obtained by calling the tools line to the piling like, and achieving unit test according to the return result of the piling like. Accordingly, the invention can greatly reduce the coding load for unit test, reduce unit test cost, and improve working efficiency.

Description

Communication function piling-like implementing method
Technical field
The present invention relates to the unit testing field, more specifically, relate to a kind of communication function piling-like implementing method.
Background technology
In present software programming, unit testing is very paid attention to.Unit testing can detect the software unit module whether correct execution its design logic, and the reaction under various boundary conditions etc.The recurrence of unit testing is carried out, and carries out modification if then can detect tested software unit module, and whether so amended new actuating logic conforms to original purpose of design, thereby finds potential problem as early as possible.
As shown in Figure 1, in network management system, can be divided into client part 102, with server end business logic processing part 104.Interface program is in service, can carry out communication by message and server end 104, issues an order to server end 104; And the message that comprises command execution results that returns of reception server end 104, presenting on the interface through resolving the back.
Therefore, in the network management interface code, have the code that numerous and server end carry out message interaction.When the unit testing use-case is carried out,, therefore, need drive piles to carrying out mutual code with server end in the tested code owing to there is not the server end environment.
But, each unit testing code at present, to tested code carry out the partial function of message interaction with server end, carried out piling class respectively and write.These piling class are that hard coded is write, and do not have versatility, can not be quoted by other unit testing code, and the workload of hard coded are huge.Therefore, need to adopt a kind of new mode to solve the network management interface unit testing and server end carries out the problem that mutual piling class is write.
Summary of the invention
In view of the above problems, the invention provides a kind of communication function piling-like implementing method,, and provide reusability so that reduce the workload that this type of piling class is write.
Communication function piling-like implementing method of the present invention may further comprise the steps: step 1 in the compiling procedure of tested code, provides the Communication Layer class, and writes the piling class and the instrument class of Communication Layer class; Step 2 in unit testing running environment, uses piling class to replace the Communication Layer class; And step 3, in the unit testing code, the calls tool class, the result that the calls tool class is obtained exports piling class to, and realizes unit testing according to the return results of piling class.
Wherein, piling class has interface identical with the Communication Layer class and extra interface, and the instrument class is used for read data files and generates the message object.
Comprise following processing in the step 3: in the unit testing code, calls tool class, thereby read data files and generate the message object; And to piling class incoming message object.
In addition, also comprise following processing in the step 3: call tested code, and tested code sends message by piling class; Piling class returned packet object; And different according to the content of message and message object, realize unit testing.
In the compiling procedure of tested code, use same Communication Layer class to carry out message interaction.
Thereby, by communication function piling-like implementing method of the present invention, can reduce the workload that piling class is write, and reusability is provided.Having solved network management interface unit testing and server carries out mutual piling class and writes problem.
Adopt the method for the invention, compared with prior art, because the unit testing code of each module all needn't be write the Communication Layer piling class of oneself, and only need provide data file to get final product, and data file much can be reused existing file, therefore make the encoding amount of unit testing significantly reduce, saved the unit testing cost, operating efficiency is provided.
Other features and advantages of the present invention will be set forth in the following description, and, partly from specification, become apparent, perhaps understand by implementing the present invention.Purpose of the present invention and other advantages can realize and obtain by specifically noted structure in the specification of being write, claims and accompanying drawing.
Description of drawings
Accompanying drawing is used to provide further understanding of the present invention, and constitutes the part of specification, is used from explanation the present invention with embodiments of the invention one, is not construed as limiting the invention.In the accompanying drawings:
Fig. 1 is the structured flowchart of network management system in the prior art;
Fig. 2 is the flow chart according to communication function piling-like implementing method of the present invention; And
Fig. 3 is the schematic diagram of employed unit testing Communication Layer piling class emulating server communication among the present invention.
Embodiment
Below in conjunction with accompanying drawing the preferred embodiments of the present invention are described, should be appreciated that preferred embodiment described herein only is used for description and interpretation the present invention, and be not used in qualification the present invention.
Fig. 2 is the flow chart according to communication function piling-like implementing method of the present invention, and Fig. 3 is the schematic diagram of employed unit testing Communication Layer piling class emulating server communication among the present invention.Describe the process of Fig. 2 in detail below with reference to Fig. 3.
At first, with reference to figure 3, when unit testing, mainly be made up of following components: unit testing code 302, data file are resolved class 304, data file 306, Communication Layer piling class 308 and tested code 310.
Next, as shown in Figure 2, communication function piling-like implementing method of the present invention may further comprise the steps:
Step S202 in the compiling procedure of tested code 310, provides the Communication Layer class, and writes the piling class 308 and the instrument class (being that data file is resolved class) 304 of Communication Layer class;
Step S204 in unit testing running environment, uses piling class 308 to replace the Communication Layer class; And
Step S206, in unit testing code 302, calls tool class 304, the result that calls tool class 304 is obtained exports piling class 308 to, and realizes unit testing according to the return results of piling class 308.
In step S202, in the compiling procedure of network management interface tested code 310, follow and use same Communication Layer class and server end to carry out the principle of message interaction, so that unit testing in the future when driving piles, is handled at a unique inlet.
Wherein, this piling class 308 has and the real the same external interface of Communication Layer class, but also provide extra interface, so that unit testing code 302 was imported the server end returned packet of simulation to passing through extra interface to this piling class 308 before test tested code 310.
Have as minor function in the real Communication Layer class, be used for sending message, and obtain the execution result message to server end:
Message?sendMessage(Message?msg);
This function parameters is the Message type, represents a message, return results also is the Message type, and expression is returned from server end, comprises the execution result information of server end to the order that comprises in the message of receiving.
Because in the unit testing environment, there is not the server end environment, so, the return results that Communication Layer piling class 308 should be able to the emulating server end.Then in Communication Layer piling class 308, Message sendMessage in having real Communication Layer class (Message msg) function, also should have an auxiliary function, so that external code (unit testing code 302) sets the return results of sendMessage function in advance.This auxiliary function is defined as follows:
public?static?void?sendMessageHelper(Message?rtnMsg){
results.add(rtnMsg);
}
Wherein, results is that type is the member variable of List, and the object of emulating server end return results message of will being used for that this function is come in unit testing code 302 transmission is stored among the formation results.
In Communication Layer piling class 308, the sendMessage function definition is as follows:
public?Message?sendMessage(Message?msg){
Message result=(Message)results.get(0)
results.remove(0);
return?result;
}
In addition, instrument class 304 can generate the message object by reading a data file 306.This object is input in the Communication Layer piling class 308 by test code.Here the data file of mentioning 306 should adopt the form that has extensively been received, so that farthest have versatility and utilize existing data file Core Generator.
In step S204, for example, the mode of using piling class 308 to replace the Communication Layer class comprises: in the classpath environmental variance is provided with, from pointing to the file at real Communication Layer class place, change the file that points to Communication Layer piling class place into.
Comprise following processing among the step S206: in unit testing code 302, calls tool class 304, thereby read data files 306 and generate the message object; And to piling class 308 incoming message objects.
Instantiation is as follows, in unit testing code 302, call data file earlier and resolve class 304, resolution data file 306, obtaining a type is Message's, the message object (for example, using temporary variable returnMessage to preserve quoting) that comprises the execution result information that simulation returns from server end to this object.
Call the sendMessageHelper function of Communication Layer piling class 308, the message of this simulation return results is joined in the return results message queue of Communication Layer piling class 308, suppose the class JunitCommunicationService by name of Communication Layer piling class 308, then call as follows:
JunitCommunicationService.sendMessageHelper(returnMessage);
In addition, also comprise following processing among the step S206: call tested code, and tested code sends message by piling class; Piling class returned packet object; And different according to the content of message and message object, realize unit testing.
Detailed process is: call tested code in the unit testing code, test code inside is running to when server end sends the statement of message, because the Communication Layer class is replaced, what then in fact call is the Communication Layer piling class, so tested code called the Communication Layer piling class after server end sends the function of message, the message of Communication Layer piling class input before returns to tested class as the return results that sends message to server, at last, the difference of the content of message that tested class is returned according to the Communication Layer piling class, and move towards different branches, thereby reach the unit testing purpose.
For example, in the unit testing code, use temporary variable modulel to quote tested class example; Comprise a functionl function among the modulel, the function that will test in the present just unit testing code.The functionl function is inner can to send message to server end, and the return results message of resolution server end.At this moment, can in unit testing code 302, call this tested function:
modulel.functionl();
Call finish after, to the value (supposing that modulel has individual member variable memberVariablel) of modulel inside member variable verify check whether it conforms to desired value:
AssertEquals (desired value, modulel.memberVariablel);
So far, finish at a unit testing use-case of the functionl method of tested class.But should be appreciated that above-mentioned example only is an example of the present invention, can't limit protection scope of the present invention.
Wherein, Communication Layer piling class and data file are resolved class and only need be write once, in each unit testing code is write, can use this two classes later on.
In addition, the form of above-mentioned data file should be all public form of network management interface and server end.Promptly by resolving this file, network management interface and server end can obtain the message object, and then this file just not only can be reused in the unit testing of a plurality of modules of network management interface, can also be reused in the unit testing of a plurality of modules of server end.
In sum, adopt method of the present invention, only need provide data file, and data file much can reuse existing file, therefore make the encoding amount of unit testing significantly reduce, save the unit testing cost, operating efficiency is provided.
Be the preferred embodiments of the present invention only below, be not limited to the present invention, for a person skilled in the art, the present invention can have various changes and variation.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (6)

1. a communication function piling-like implementing method is characterized in that, may further comprise the steps:
Step 1 in the compiling procedure of tested code, provides the Communication Layer class, and writes the piling class and the instrument class of described Communication Layer class;
Step 2 in unit testing running environment, uses described piling class to replace described Communication Layer class; And
Step 3 in the unit testing code, is called described instrument class, exports described piling class to calling the result that described instrument class obtains, and realizes unit testing according to the return results of described piling class.
2. method according to claim 1 is characterized in that, described piling class has interface identical with described Communication Layer class and extra interface.
3. method according to claim 1 is characterized in that, described instrument class is used for read data files and generates the message object.
4. method according to claim 1 is characterized in that, comprises following processing in the described step 3:
In described unit testing code, call described instrument class, thereby read described data file and generate described message object; And
Import described message object to described piling class.
5. method according to claim 4 is characterized in that, also comprises following processing in the described step 3:
Call tested code, and described tested code sends message by described piling class;
Described piling class returns described message object; And
Different according to the content of described message and described message object are realized unit testing.
6. method according to claim 1 is characterized in that, in the compiling procedure of described tested code, uses same Communication Layer class to carry out message interaction.
CNA2007101114616A 2007-06-20 2007-06-20 Implementation method for piling class of communication function Pending CN101145954A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNA2007101114616A CN101145954A (en) 2007-06-20 2007-06-20 Implementation method for piling class of communication function

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNA2007101114616A CN101145954A (en) 2007-06-20 2007-06-20 Implementation method for piling class of communication function

Publications (1)

Publication Number Publication Date
CN101145954A true CN101145954A (en) 2008-03-19

Family

ID=39208268

Family Applications (1)

Application Number Title Priority Date Filing Date
CNA2007101114616A Pending CN101145954A (en) 2007-06-20 2007-06-20 Implementation method for piling class of communication function

Country Status (1)

Country Link
CN (1) CN101145954A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016065753A1 (en) * 2014-10-28 2016-05-06 中兴通讯股份有限公司 Test method, device and system
WO2018036273A1 (en) * 2016-08-22 2018-03-01 上海壹账通金融科技有限公司 Simulation test method, server, device, and computer-readable storage medium
CN109308260A (en) * 2018-08-30 2019-02-05 福建天泉教育科技有限公司 A kind of method and terminal of automatically generating unit test code

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016065753A1 (en) * 2014-10-28 2016-05-06 中兴通讯股份有限公司 Test method, device and system
WO2018036273A1 (en) * 2016-08-22 2018-03-01 上海壹账通金融科技有限公司 Simulation test method, server, device, and computer-readable storage medium
CN109308260A (en) * 2018-08-30 2019-02-05 福建天泉教育科技有限公司 A kind of method and terminal of automatically generating unit test code
CN109308260B (en) * 2018-08-30 2021-11-05 福建天泉教育科技有限公司 Method and terminal for automatically generating unit test code

Similar Documents

Publication Publication Date Title
CN101930400B (en) SDK (Software Development Kit) automatic test system and method
CN101482817B (en) Large-particle Java component assembly method based on black box
CN108845940B (en) Enterprise-level information system automatic function testing method and system
CN112835560A (en) WEB multi-terminal low-code intelligent software development platform
CN103425572B (en) Code analysis methods and code analysis system
CN104683386A (en) Pile service implementation method and device capable of customizing response
CN104331366A (en) Test case design efficiency promotion method and system
Weigert et al. Practical experiences in using model-driven engineering to develop trustworthy computing systems
CN101841515A (en) Target variable protocol data unit codec code automatic generation implementation method
CN102819766A (en) Method, device and enterprise system for checking forms
CN101976199A (en) Object-oriented middleware distributed system development platform
Bellettini et al. Mardigras: Simplified building of reachability graphs on large clusters
CN104765603A (en) Application program building method and device
CN101980546B (en) Intelligent network platform, service execution method and method for analyzing service abnormality
CN111782207A (en) Method, device and equipment for generating task stream code and storage medium
CN101196812A (en) Method for script language calling multiple output parameter interface by component software system
CN111026660A (en) Penetration testing method based on expert system knowledge base
CN102609357B (en) Method for dynamically building test cases for automatic testing meeting AUTOSAR (automotive open system architecture) standards
CN111176660A (en) Distributed architecture-oriented micro-service contract management method and device, computer equipment and readable storage medium
Schieferdecker et al. A meta-model for TTCN-3
CN101145954A (en) Implementation method for piling class of communication function
CN101296462A (en) Method and system for batch execution of mobile terminal software automatic test
CN103561113A (en) Web Service interface generating method and device
EP3005087A1 (en) Declarative configuration elements
TW201407503A (en) System and method for work schedule of cloud platform

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Open date: 20080319