Summary of the invention
The embodiment of the present application provides the generation method and device of a kind of test data, to improve the effective of test result
Property.
Specific technical solution provided by the embodiments of the present application is as follows:
A kind of generation method of test data, comprising:
The request message that called side is sent is received, is sent to service side after carrying out data record, and receive server and return
Response message, carry out data record after be sent to called side;
Unserializing processing is carried out to the data of record, obtains code elements information;
Code elements information based on acquisition generates corresponding test code.
In this way, code can be tested accordingly based on true Application of Interface environment generation, to effectively increase test
The formation efficiency of code improves the validity and accuracy of test result, while the exploitation of test code is also greatly saved
And maintenance cost.Further, the versatility of the embodiment of the present application is high, is suitable for various protocol interfaces, and easy to operate, no
Need developer that there is the development Experience of many years, so that reducing it into one extends cost.
Optionally, the request message that called side is sent is received, is sent to service side after carrying out data record, and receive service
The response message that device returns is sent to called side after carrying out data record, comprising:
When receiving the request message of called side transmission, the specific field in the request message is read, according to described
The type of the parsing result decision request message of specific field, and obtain the system domain name of service side;
If the request message is to obtain get request message, the binary data in start recording get request message,
After record, the local connection to service side is opened according to the system domain name of service side, and get request message is passed through into institute
It states connection and is sent to service side, and in the response message for receiving service side, the binary data of recording responses message, and
It is back to called side;
If the request message is publication post request message, is opened according to the system domain name of service side and locally extremely serviced
The connection of side, the binary data in start recording post request message, and circulation reading is carried out to post request message, it will
It records the data portion finished and service side is successively sent to by the connection, and disappear in the response for receiving service side's return
When breath, the binary data of recording responses message, and circulation reading is carried out to response message, the data portion finished will have been recorded
Successively it is sent to called side.
Optionally, unserializing processing is carried out to the data of record, obtains code elements information, comprising:
What it is by record includes that the binary data of request message and response message is converted to character string, and therefrom parses
Used calling interface and call method when called side is called service side;
String data progress unserializing processing to acquisition, the acquisition operable test object of java applet, and from
In parse the call result for entering to join list and service side and returning used when called side is called service side;
By the calling interface of acquisition, call method, enter to join list and call result is determined as code elements information.
Optionally, the code elements information based on acquisition generates corresponding test code, comprising:
According to the calling interface that the called side of acquisition uses, calling interface title and calling used in code are tested in configuration
Call method title, called side used in code are tested in interface type, and the call method used according to called side, configuration
Method type and call parameters;
To used based on called side enter to join test object that the call result that list and service side return generates respectively into
Row parsing, acquisition enter join title, enter to join type, enter to join assignment and result parameter title, result parameter type, result accordingly
Parameter assignment, and corresponding test code is generated according to information is obtained.
Optionally, further comprise:
It is carried out to the test object of the call result generation for entering to join list and service side's return used based on called side
During Parameter analysis of electrochemical, if test object to be obtained is plain objects, directly it is called;If test pair to be obtained
Address is saved as complex object, then reading the corresponding file of the complex object to obtain and generate based on the complex object
File is saved, and is called again after the preservation file is converted to the complex object.
A kind of generating means of test data, comprising:
Communication unit is sent to service side, Yi Jijie after carrying out data record for receiving the request message of called side transmission
The response message that server returns is received, is sent to called side after carrying out data record;
Processing unit carries out unserializing processing for the data to record, obtains code elements information;
Generation unit generates corresponding test code for the code elements information based on acquisition.
In this way, code can be tested accordingly based on true Application of Interface environment generation, to effectively increase test
The formation efficiency of code improves the validity and accuracy of test result, while the exploitation of test code is also greatly saved
And maintenance cost.Further, the versatility of the embodiment of the present application is high, is suitable for various protocol interfaces, and easy to operate, no
Need developer that there is the development Experience of many years, so that reducing it into one extends cost.
Optionally, the request message that called side is sent is received, is sent to service side after carrying out data record, and receive service
The response message that device returns carries out after data record when being sent to called side, and the communication unit is specifically used for:
When receiving the request message of called side transmission, the specific field in the request message is read, according to described
The type of the parsing result decision request message of specific field, and obtain the system domain name of service side;
If the request message is to obtain get request message, the binary data in start recording get request message,
After record, the local connection to service side is opened according to the system domain name of service side, and get request message is passed through into institute
It states connection and is sent to service side, and in the response message for receiving service side, the binary data of recording responses message, and
It is back to called side;
If the request message is publication post request message, is opened according to the system domain name of service side and locally extremely serviced
The connection of side, the binary data in start recording post request message, and circulation reading is carried out to post request message, it will
It records the data portion finished and service side is successively sent to by the connection, and disappear in the response for receiving service side's return
When breath, the binary data of recording responses message, and circulation reading is carried out to response message, the data portion finished will have been recorded
Successively it is sent to called side.
Optionally, unserializing processing is carried out to the data of record, when obtaining code elements information, the recording unit tool
Body is used for:
What it is by record includes that the binary data of request message and response message is converted to character string, and therefrom parses
Used calling interface and calling device when called side is called service side;
String data progress unserializing processing to acquisition, the acquisition operable test object of java applet, and from
In parse the call result for entering to join list and service side and returning used when called side is called service side;
By the calling interface of acquisition, call method, enter to join list and call result is determined as code elements information.
Optionally, when the code elements information based on acquisition generates corresponding test code, the generation unit is specifically used
In:
According to the calling interface that the called side of acquisition uses, calling interface title and calling used in code are tested in configuration
Interface type, and the calling device used according to called side, configuration test calling device title used in code, call dress
Set type and call parameters;
To used based on called side enter to join test object that the call result that list and service side return generates respectively into
Row parsing, acquisition enter join title, enter to join type, enter to join assignment and result parameter title, result parameter type, result accordingly
Parameter assignment, and corresponding test code is generated according to information is obtained.
Optionally, the generation unit is further used for:
It is carried out to the test object of the call result generation for entering to join list and service side's return used based on called side
During Parameter analysis of electrochemical, if test object to be obtained is plain objects, directly it is called;If test pair to be obtained
Address is saved as complex object, then reading the corresponding file of the complex object to obtain and generate based on the complex object
File is saved, and is called again after the preservation file is converted to the complex object.
Specific embodiment
In order to improve the test result validity of interface testing, in the embodiment of the present application, test data has been redesigned
Generating mode, i.e., by monitoring transmission control protocol (TransmissionControl Protocol, TCP) data then inverted sequence
Columnization, thus the test data needed for being generated based on truthful data, completely without manual construction data, that is, when saving test
Between, and because of the authenticity of test data, effectively improve the validity of test result.
The application preferred embodiment is described in detail with reference to the accompanying drawing.
As shown in fig.1, being provided with the agency positioned at TCP layer between called side and service side in the embodiment of the present application
System, referred to as, TCP agent system, any request for calling direction service side to send all can be received and be forwarded by TCP agent system
To service side, correspondingly, any response that service side returns also all can be forwarded to called side by TCP agent system work.
In specific implementation, as long as the destination service of called side, which is switched to TCP agent system, will e.g. call
The service domain name of side is directed toward TCP agent system etc., and this is no longer going to repeat them.In addition, tester can pass through any side
Formula can also be returned to call by service orientation called side and be rung in any manner by calling direction service side to send call request
It answers, all operating process by TCP agent system forwards and can all record.
As shown in fig.2, the general introduction process that TCP agent system generates test data is as follows in the embodiment of the present application:
Step 200: receiving the request message that called side is sent, be sent to service side after carrying out data record, and receive clothes
The response message that business device returns, is sent to called side after carrying out data record.
As shown in Figure 1, TCP agent system forwards between the two between called side and service side in the embodiment of the present application
Interaction message, during forwarding, optionally, TCP agent system records interaction message between the two, packet in TCP layer
Include that called side is sent to the request message of service side and service side is sent to the response message of called side.Due to being carried out in TCP layer
Data decryptor, therefore, the embodiment of the present application are a kind of general schemes, are adapted to the system using any protocol stack and set
It is standby, as long as accordingly being developed based on TCP layer, so that it may carry out the monitoring of any type interface service agreement.
On the other hand, the application supports the network service (Webservice, wb) of xfire and some customized at present
Far call agreement can also suitably extend the agreement that technical scheme is paid according to practical application request,
In the present embodiment, function presentation only is done in a manner of the ws protocol processes of xfire.
Specifically, TCP agent system is mainly used for the request message for sending called side, forwarding when executing step 200
Called side is returned to specified service side, and by the response message that service side returns, and in this calling process, record
The binary data of request message and response message.
In practical application, request message is divided into acquisition (get) request message and publication (post) request message, the former is used for
Service description language (sdl) (Web Services Description Languag, wsdl) document (i.e. service side is requested to service side
Enter to join list), the latter is for calling service side to execute various operations.For different types of request message, TCP agent system
Different processing will be executed.Wherein, Web service description is defined as one group of service access point by wsdl document, and client can lead to
These service access points are crossed to access (similar to remote process tune to the service comprising Oriented Documents information or procedure-oriented calling
With).
Specific executive mode is as follows:
It after the starting of TCP agent system, monitors designated port (e.g., being configured to 8080 ports), is requested when receiving called side
When message, the specific field in TCP agent system read requests message is (for example, preceding 256 bytes or preceding 1024 bytes etc.
Deng), according to the type of the parsing result decision request message of this partial data, and the system domain name of service side is obtained, it is also referred to as main
Machine (host) information;
If request message be get request message, the purpose is to obtain service side wsdl document (i.e. service side enter ginseng
List), it is so-called enter to join list be that parameter list to be used is needed when calling service side, called side is according to entering to join the prompt of list
Service side can be called by filling corresponding parameter in post request.So, TCP agent system start recording get
Binary data in request message, and after record, it is opened according to the system domain name of service side local to service side's
Get request message is sent to service side by established TCP connection by TCP connection;Correspondingly, TCP agent system is receiving
To service side response message (carry wsdl file) when, the binary data of recording responses message, and be back to called side.
Why in this way processing is less because of the data volume carried in get request message, it can be finished in record
Afterwards, all data are sent to service side together.
If post request message, then the purpose is to call service side to complete various operations, then, TCP agent system root
The local TCP connection to service side is opened according to the system domain name of service side, this TCPL is written into the specific field that early period reads and is connected
Meet (all data will incoming service side, first will acquire the data received herein and first send), and start recording post
Binary data (optional, request array to can be used, i.e., byte [], request was recorded) in request message, connects
, TCP agent system can carry out circulation reading to post request message, will record the data portion finished by having been established
TCP connection be successively sent to service side;Correspondingly, the response message that TCP agent system receives service side's return (is carried and is adjusted
With result) when, (response array, i.e. byte [] response optionally, can be used in the binary data of recording responses message
Recorded), and circulation reading is carried out to response message, the data portion finished will have been recorded and be successively sent to called side.
Wherein, when to service side's returning response message, in order to avoid reading empty data, optionally, TCP agent system can
It is slept 25 milliseconds of (sleep) with circulation, is until the data recorded in byte [] response contain wsdl ending identifier
Only.
Why in this way processing is because the data volume carried in post request message is more, in order to avoid causing data to hinder
Post request message is sent to service side several times by plug, TCP processing system.
Step 210: unserializing processing being carried out to the data of record, obtains code elements information.
When executing step 210, TCP processing system specifically executes following steps:
Firstly, TCP agent system obtain recorded binary data (include: get request message and its response message,
Post request message and its response message), binary data is converted into character string, and therefrom parse called side to service side
Used calling interface and call method when being called.
In practical application, all data record in binary form, and TCP agent system is carrying out unserializing behaviour
It before work, needs that binary data is first converted to character string (e.g., soap version of an agreement), after being converted to character string, call
The calling interface and call method of Fang Caiyong can directly parse acquisition, and enter to join list and be related to complicated parameter configuration, adjust
Also include mass data with result, acquisition can not be parsed under character string state, it is necessary to carry out unserializing operation, be converted to
The operable object of java applet.
Secondly, the string data to acquisition carries out unserializing processing, the operable test object of java applet is obtained,
And therefrom parse used when called side is called service side enter to join list, use enter to join list and service side returns
The calling returned obtains the operable test object of java applet.
Finally, by the calling interface of acquisition, call method, entering to join list and call result is determined as code elements information.
In the embodiment of the present application, TCP agent system, which executes unserializing operation, to be realized based on the transformation to xfire
, xFire is of new generationJavaWeb service engine, for simplifying the step of Java application is converted into Web service and process,
In the present embodiment, the function of xfire processor has been transformed, has only remained its data parsing function, other services is not provided, because
This, the unserializing that TCP agent system need to only call improved xfire that data can be realized operates.It is grasped by unserializing
After work, TCP agent system can be parsed out the call result for entering to join list and service side's return that called side uses, both of which
It is converted into the operable test object of java applet, wherein due to entering to join in list and call result include a large amount of multiple
Miscellaneous data, therefore, the object of generation include plain objects and complex object.
Above-mentioned calling interface, call method enter to join list and call result and are important code elements information, by these
The accurate test code for meeting actual application environment can be generated as dimension in information;Certainly, if administrative staff are known in advance
The calling interface and call method that called side uses, then TCP agent system can not also parse from character string and obtain this information,
And unserializing operation only is carried out to character string and obtains mostly important to enter to join list and call result.It is no longer superfluous herein
It states.
Step 220: the code elements information based on acquisition generates corresponding test code.
Specifically, TCP code system executes following operation when executing step 220:
Firstly, according to the calling interface that the called side of acquisition uses, calling interface title used in configuration test code
With calling interface type, and call method title used in the call method configuration test code that is used according to called side,
Call method type and call parameters.
For example, the calling interface and call method that are used according to called side, interface name used in configuration test code,
A kind of bean (java class) type, bean title, call parameters method etc.;Wherein, for simple parameter variable and parameter piece
Act value needs to carry out initial assignment.
Secondly, the test object point to the call result generation for entering to join list and service side's return used based on called side
Do not parsed, obtain accordingly enter join title, enter to join type, enter to join assignment and result parameter title, result parameter type,
Result parameter assignment, and corresponding test code is generated according to information is obtained.
For example, can be parsed to entering to join list for entering and joining list, in test code with merging ginseng type,
Enter ginseng statement, import type, initialization assignment etc..
On the other hand, after to entering to join list and call result progress unserializing operation, due to the test object of generation
It may be plain objects and complex object, therefore, preserving type may be different, and e.g., plain objects are directly with Java object
Form saves, and complex object needs to be saved more safe safety with document form since data volume is huge, therefore, TCP
Agency plant needs to be converted to complex object document form (e.g., Javascript Object Notation (Javascript Object
Notation, Json) save file) saved, and record file and save address.) stored, and record file and save ground
Location.
In this way, in the test object to the call result generation for entering to join list and service side's return used based on called side
During carrying out Parameter analysis of electrochemical, if test object to be obtained is plain objects, TCP agent system is directly called,
The Java object of corresponding preservation is directly read, and if test object to be obtained is complex object, the reading of TCP agent system
The corresponding file of the complex object saves address to obtain the preservation file generated based on the complex object, and by the preservation file
Corresponding complex object is converted to be called again.
Using the above method, can gradually be given birth to (i.e. since the part package) since the initial part of test code
At the interface testing code of a standard.
As shown in fig.3, in the embodiment of the present application, a kind of generating means of test data (i.e. TCP agent system), including
Communication unit 30, processing unit 31 and generation unit 32, wherein
Communication unit 30, the request message sent for receiving called side, is sent to service side after carrying out data record, and
The response message that server returns is received, is sent to called side after carrying out data record;
Processing unit 31 carries out unserializing processing for the data to record, obtains code elements information;
Generation unit 32 generates corresponding test code for the code elements information based on acquisition.
Optionally, communication unit is specifically used for:
When receiving the request message of called side transmission, specific field in read requests message, according to specific field
Parsing result decision request message type, and obtain the system domain name of service side;
If request message is to obtain get request message, the binary data in start recording get request message is being remembered
After record, the local connection to service side is opened according to the system domain name of service side, and get request message is passed through into connection hair
It send to service side, and in the response message for receiving service side, the binary data of recording responses message, and is back to tune
With side;
If request message is publication post request message, opened according to the system domain name of service side local to service side's
It connects, the binary data in start recording post request message, and circulation reading is carried out to post request message, will record
The data portion finished is successively sent to service side by connection, and when receiving the response message of service side's return, note
The binary data of response message is recorded, and circulation reading is carried out to response message, the data portion finished will have been recorded and successively sent out
Give called side.
Optionally, recording unit is specifically used for:
What it is by record includes that the binary data of request message and response message is converted to character string, and therefrom parses
Used calling interface and calling device when called side is called service side;
String data progress unserializing processing to acquisition, the acquisition operable test object of java applet, and from
In parse the call result for entering to join list and service side and returning used when called side is called service side;
By the calling interface of acquisition, call method, enter to join list and call result is determined as code elements information.
Optionally, generation unit is specifically used for:
According to the calling interface that the called side of acquisition uses, calling interface title and calling used in code are tested in configuration
Interface type, and the calling device used according to called side, configuration test calling device title used in code, call dress
Set type and call parameters;
To used based on called side enter to join test object that the call result that list and service side return generates respectively into
Row parsing, acquisition enter join title, enter to join type, enter to join assignment and result parameter title, result parameter type, result accordingly
Parameter assignment, and corresponding test code is generated according to information is obtained.
Optionally, generation unit is further used for:
It is carried out to the test object of the call result generation for entering to join list and service side's return used based on called side
During Parameter analysis of electrochemical, if test object to be obtained is plain objects, directly it is called;If test pair to be obtained
Address is saved as complex object, then reading the corresponding file of complex object to obtain the preservation text generated based on complex object
Part, and will save after file is converted to complex object and be called again.
In conclusion in the embodiment of the present application, TCP agent system in data transmission procedure to transmission data carry out two into
Data record processed, then unserializing operation is carried out to the binary data of record, code elements information is obtained, and be based on code
Element information generates required test code, in this way, code can be tested based on true Application of Interface environment generation accordingly,
To effectively increase the formation efficiency of test code, the validity and accuracy of test result are improved, while also saving significantly
The development and maintenance cost of test code is saved.Further, the versatility of the embodiment of the present application is high, is suitable for various agreements
Interface, and it is easy to operate, the development Experience that developer has many years is not needed, so that reducing it into one extends cost.
It should be understood by those skilled in the art that, embodiments herein can provide as method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the application
Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the application, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
The application is referring to method, the process of equipment (system) and computer program product according to the embodiment of the present application
Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions
The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs
Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce
A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real
The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
Although the preferred embodiment of the application has been described, it is created once a person skilled in the art knows basic
Property concept, then additional changes and modifications may be made to these embodiments.So it includes excellent that the following claims are intended to be interpreted as
It selects embodiment and falls into all change and modification of the application range.
Obviously, those skilled in the art can carry out various modification and variations without departing from this Shen to the embodiment of the present application
Please embodiment spirit and scope.In this way, if these modifications and variations of the embodiment of the present application belong to the claim of this application
And its within the scope of equivalent technologies, then the application is also intended to include these modifications and variations.