Summary of the invention
The embodiment of the present application provides a kind of generation method and device of test data, in order to improve the validity of test result.
The concrete technical scheme that the embodiment of the present application provides is as follows:
A generation method for test data, comprising:
Receive the request message that called side sends, after carrying out data record, mail to service side, and the response message that reception server returns, mail to called side after carrying out data record;
Unserializing process is carried out to the data of record, obtains code elements information;
Corresponding test code is generated based on the code elements information obtained.
Like this, based on the corresponding test code of real Application of Interface environment generation, thus can effectively improve the formation efficiency of test code, improve validity and the accuracy of test result, also greatly save the development and maintenance cost of test code simultaneously.Further, the versatility of the embodiment of the present application is high, is applicable to various protocol interface, and simple to operate, does not need developer to have development Experience for many years, thus enters one and reduce its expansion cost.
Optionally, receive the request message that called side sends, after carrying out data record, mail to service side, and the response message that reception server returns, mail to called side after carrying out data record, comprising:
When receiving the request message that called side sends, reading the specific field in described request message, according to the type of the analysis result decision request message of described specific field, and obtaining the system domain name of service side;
If described request message is for obtaining get request message, then start to record the binary data in 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 sent to service side by described connection, and when receiving the response message of service side, the binary data of recording responses message, and be back to called side;
If described request message is for issuing post request message, then open the local connection to service side according to the system domain name of service side, start to record the binary data in post request message, and circulation reading is carried out to post request message, service side is sent to successively by described connection by recording complete data division, and when receiving the response message that service side returns, the binary data of recording responses message, and circulation reading is carried out to response message, send to called side successively by recording complete data division.
Optionally, unserializing process is carried out to the data of record, obtains code elements information, comprising:
The binary data including request message and response message of record is converted to character string, and therefrom parses the calling interface and call method that adopt when called side is called service side;
Unserializing process is carried out to the string data obtained, obtains java applet exercisable tested object, and therefrom parse use when called side is called service side enter to join list, and service side return call result;
By the calling interface of acquisition, call method, enter to join list and call result to be defined as code elements information.
Optionally, generate corresponding test code based on the code elements information obtained, comprising:
According to the calling interface that the called side obtained uses, the calling interface title used in configuration testing code and calling interface type, and according to the call method that called side uses, the call method title used in configuration testing code, call method type and call parameters;
Enter to join that list and service side return calls the tested object that result generates and resolve respectively to what use based on called side, acquisition enters to join title accordingly, enters to join type, enters to join assignment and result parameter title, result parameter type, result parameter assignment, and generates corresponding test code according to the information of acquisition.
Optionally, comprise further:
Entering to join that list and service side return calls the tested object that result generates and carry out in the process of Parameter analysis of electrochemical to what use based on called side, if tested object to be obtained is plain objects, then directly call; If tested object to be obtained is complex object, then reads file corresponding to described complex object and preserve address to obtain the preservation file generated based on described complex object, and be call again after described complex object by described preservation file transform.
A generating apparatus for test data, comprising:
Communication unit, for receiving the request message that called side sends, mails to service side after carrying out data record, and the response message that reception server returns, and mails to called side after carrying out data record;
Processing unit, for carrying out unserializing process to the data of record, obtains code elements information;
Generation unit, for generating corresponding test code based on the code elements information obtained.
Like this, based on the corresponding test code of real Application of Interface environment generation, thus can effectively improve the formation efficiency of test code, improve validity and the accuracy of test result, also greatly save the development and maintenance cost of test code simultaneously.Further, the versatility of the embodiment of the present application is high, is applicable to various protocol interface, and simple to operate, does not need developer to have development Experience for many years, thus enters one and reduce its expansion cost.
Optionally, receive the request message that called side sends, mail to service side after carrying out data record, and the response message that reception server returns, when mailing to called side after carrying out data record, described communication unit specifically for:
When receiving the request message that called side sends, reading the specific field in described request message, according to the type of the analysis result decision request message of described specific field, and obtaining the system domain name of service side;
If described request message is for obtaining get request message, then start to record the binary data in 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 sent to service side by described connection, and when receiving the response message of service side, the binary data of recording responses message, and be back to called side;
If described request message is for issuing post request message, then open the local connection to service side according to the system domain name of service side, start to record the binary data in post request message, and circulation reading is carried out to post request message, service side is sent to successively by described connection by recording complete data division, and when receiving the response message that service side returns, the binary data of recording responses message, and circulation reading is carried out to response message, send to called side successively by recording complete data division.
Optionally, to record data carry out unserializing process, obtain code elements information time, described record cell specifically for:
The binary data including request message and response message of record is converted to character string, and therefrom parses the calling interface and calling device that adopt when called side is called service side;
Unserializing process is carried out to the string data obtained, obtains java applet exercisable tested object, and therefrom parse use when called side is called service side enter to join list, and service side return call result;
By the calling interface of acquisition, call method, enter to join list and call result to be defined as code elements information.
Optionally, based on obtain code elements information generate corresponding test code time, described generation unit specifically for:
According to the calling interface that the called side obtained uses, the calling interface title used in configuration testing code and calling interface type, and according to the calling device that called side uses, the calling device title used in configuration testing code, calling device type and call parameters;
Enter to join that list and service side return calls the tested object that result generates and resolve respectively to what use based on called side, acquisition enters to join title accordingly, enters to join type, enters to join assignment and result parameter title, result parameter type, result parameter assignment, and generates corresponding test code according to the information of acquisition.
Optionally, described generation unit is further used for:
Entering to join that list and service side return calls the tested object that result generates and carry out in the process of Parameter analysis of electrochemical to what use based on called side, if tested object to be obtained is plain objects, then directly call; If tested object to be obtained is complex object, then reads file corresponding to described complex object and preserve address to obtain the preservation file generated based on described complex object, and be call again after described complex object by described preservation file transform.
Embodiment
In order to improve the test result validity of interface testing, in the embodiment of the present application, redesign the generating mode of test data, namely by monitoring transmission control protocol (TransmissionControlProtocol, TCP) data then unserializing, thus the test data needed for generating based on True Data, do not need manual construction data completely, namely save the test duration, again because the authenticity of test data, effectively improve the validity of test result.
Below in conjunction with accompanying drawing, the application is preferred embodiment described in detail.
Consult shown in Fig. 1, in the embodiment of the present application, the agency plant being positioned at TCP layer is provided with between called side and service side, be called for short, TCP agent system, any request that call direction service side sends all can be forwarded to service side by TCP agent system acceptance, and accordingly, any response that service side returns also all can be forwarded to called side by TCP agent system work.
When specific implementation, as long as be switched to TCP agent system by the destination service of called side, e.g., the service domain name of called side is pointed to TCP agent system etc., and this is no longer going to repeat them.In addition, tester can send call request by any mode by call direction service side, also can be returned by service orientation called side by any mode and call response, and all operating process all can by TCP agent system forwards and record.
Consult shown in Fig. 2, in the embodiment of the present application, the general introduction flow process that TCP agent system generates test data is as follows:
Step 200: receive the request message that called side sends, mail to service side after carrying out data record, and the response message that reception server returns, mail to called side after carrying out data record.
As shown in Figure 1, in the embodiment of the present application, TCP agent system forwards interaction message between the two between called side and service side, in the process forwarded, optionally, TCP agent system, at TCP layer record interaction message between the two, comprise the request message that called side mails to service side, and service side mails to the response message of called side.Owing to having carried out data decryptor at TCP layer, therefore, the embodiment of the present application is a kind of general scheme, can be adapted to the system and the equipment that adopt any protocol stack, as long as carry out corresponding exploitation based on TCP layer, just can carry out the monitoring of any style interface service agreement.
On the other hand, the application supports the network service (Webservice of xfire at present, and some self-defining far call agreements wb), according to practical application request, also can the agreement that technical scheme pays suitably be expanded, in the present embodiment, only do function presentation in the ws protocol processes mode of xfire.
Concrete, when performing step 200, TCP agent system is mainly used in request message called side sent, be forwarded to the service side specified, and response message service side to be returned returns to called side, and in this invoked procedure, the binary data of record request message and response message.
In practical application, request message is divided into acquisition (get) request message and issue (post) request message, the former is for service side's request service descriptive language (WebServicesDescriptionLanguag, wsdl) document (i.e. service side enter to join list), the latter is used for calling service side and performs various operation.For dissimilar request message, TCP agent system will perform different process.Wherein, Web service describes and is defined as one group of service access point by wsdl document, and client can conduct interviews (similar remote procedure call) by these service access points to comprising the service that Oriented Documents information or procedure-oriented call.
Concrete executive mode is as follows:
After TCP agent system starts, monitoring designated port (as, be configured to 8080 ports), when receiving called side request message, specific field (such as, front 256 bytes or front 1024 bytes etc.) in TCP agent system read requests message, according to the type of the analysis result decision request message of this part data, and obtain the system domain name of service side, also claim main frame (host) information;
If request message is get request message, then its objective is the wsdl document (i.e. service side enter to join list) obtaining service side, namely what is called enters to join list is the parameter list needing when calling service side to use, and called side fills corresponding parameter according to the prompting entering to join list and can call service side in post request.So, TCP agent system starts to record the binary data in get request message, and after record, opens the local TCP to service side connect according to the system domain name of service side, is connected by get request message be sent to service side by the TCP set up; Accordingly, TCP agent system when receiving the response message of service side (carrying wsdl file), the binary data of recording responses message, and be back to called side.
Why like this process is because the data volume of carrying in get request message is less, therefore, after record, all data can be sent to service side together.
If post request message, then its objective is that calling service side completes various operation, so, TCP agent system is opened the local TCP to service side according to the system domain name of service side and is connected, (all data all will import service side into the specific field that early stage reads to be write this TCPL connection, first first send obtaining the data received) herein, and the binary data starting to record in post request message is (optional, request array can be used, namely byte [] request records), then, TCP agent system can be carried out circulation to post request message and be read, service side is sent to successively by the TCP connection of having set up by recording complete data division, accordingly, time response message (carry and call result) that TCP agent system acceptance returns to service side, the binary data of recording responses message is (optional, response array can be used, namely byte [] response records), and circulation reading is carried out to response message, send to called side successively by recording complete data division.
Wherein, when returning response message to service side, in order to avoid reading empty data, optionally, TCP agent system can circulate sleep (sleep) 25 milliseconds, to end up identifier until the data recorded in byte [] response contain wsdl.
Why like this process is that in order to avoid causing data jamming, post request message is sent to service side by TCP disposal system several times because the data volume of carrying in post request message is more.
Step 210: carry out unserializing process to the data of record, obtains code elements information.
When performing step 210, TCP disposal system specifically performs following steps:
First, TCP agent system obtains the binary data recorded and (comprising: get request message and response message thereof, post request message and response message thereof), binary data is converted to character string, and therefrom parses the calling interface and call method that adopt when called side is called service side.
In practical application, all data record all in binary form, TCP agent system is before carrying out unserializing operation, need first binary data is converted to character string (as, soap version of an agreement), after being converted to character string, the calling interface that called side adopts and call method directly can resolve acquisition, and enter to join the parameter configuration that list relates to complexity, call result and also comprise mass data, acquisition cannot be resolved under character string state, must unserializing operation be carried out, be converted to the exercisable object of java applet.
Secondly, unserializing process is carried out to the string data obtained, obtain the exercisable tested object of java applet, and therefrom parse use when called side is called service side enter to join list, the calling that list and service side return that enter to join of use obtains the exercisable tested object of java applet.
Finally, by the calling interface of acquisition, call method, enter to join list and call result to be defined as code elements information.
In the embodiment of the present application, it is that xFire is of new generation based on what realize the transformation of xfire that TCP agent system performs unserializing operation
javaweb service engine, step and the process of Web service is converted into for simplifying Java application, in the present embodiment, transform the function of xfire processor, only remain its Data Analysis function, do not provide other to serve, therefore, TCP agent system only need call the unserializing operation that improved xfire can realize data.After unserializing operation, what what TCP agent system can parse that called side uses enter to join list and service side returned calls result, both is all converted into the exercisable tested object of java applet, wherein, owing to entering to join list and calling the data all including large amount of complex in result, therefore, the object of generation comprises plain objects and complex object.
Above-mentioned calling interface, call method, to enter to join list and call result be all important code elements information, using these information as dimension, can generate the test code accurately of realistic applied environment; Certainly, if managerial personnel know the calling interface that called side adopts and call method in advance, then TCP agent system also can not be resolved and be obtained this information from character string, and only carries out unserializing operation to character string and obtain of paramount importancely enter to join list and call result.Do not repeat them here.
Step 220: generate corresponding test code based on the code elements information obtained.
Concrete, when performing step 220, TCP code system performs following operation:
First, according to the calling interface that the called side obtained uses, the calling interface title used in configuration testing code and calling interface type, and the call method title, call method type and the call parameters that use in the call method configuration testing code used according to called side.
Such as, the calling interface used according to called side and call method, the interface name used in configuration testing code, bean (a kind of java class) type, bean title, call parameters method etc.; Wherein, simple parameter variable and parameter enumerated value are needed to carry out initial assignment.
Secondly, enter to join that list and service side return calls the tested object that result generates and resolve respectively to what use based on called side, acquisition enters to join title accordingly, enters to join type, enters to join assignment and result parameter title, result parameter type, result parameter assignment, and generates corresponding test code according to the information of acquisition.
Such as, to enter to join list, can resolve entering to join list, configuring into ginseng type in test code, entering ginseng statement, import type, initialization assignment etc.
On the other hand, to entering to join list and calling after result carries out unserializing operation, because the tested object generated may be plain objects and complex object, therefore, its preserving type may be different, as, plain objects is directly preserved with the form of Java object, and complex object due to data volume huge, need to carry out preserving more safe safety with document form, therefore, TCP agent system need complex object to be converted to document form (as, Javascript Object Notation (JavascriptObjectNotation, Json) file is preserved) preserve, and address preserved by log file.) store, and address preserved by log file.
Like this, entering to join that list and service side return calls the tested object that result generates and carry out in the process of Parameter analysis of electrochemical to what use based on called side, if tested object to be obtained is plain objects, then TCP agent system is directly called, namely corresponding Java object of preserving directly is read, if and tested object to be obtained is complex object, then TCP agent system reads file corresponding to this complex object and preserves address to obtain the preservation file generated based on this complex object, and is that corresponding complex object calls again by this preservation file transform.
Adopt said method, can from the initial part of test code (namely from package part) progressively generate the interface testing code of a standard.
Consult shown in Fig. 3, in the embodiment of the present application, a kind of generating apparatus (i.e. TCP agent system) of test data, comprises communication unit 30, processing unit 31 and generation unit 32, wherein,
Communication unit 30, for receiving the request message that called side sends, mails to service side after carrying out data record, and the response message that reception server returns, and mails to called side after carrying out data record;
Processing unit 31, for carrying out unserializing process to the data of record, obtains code elements information;
Generation unit 32, for generating corresponding test code based on the code elements information obtained.
Optionally, communication unit specifically for:
When receiving the request message that called side sends, the specific field in read requests message, according to the type of the analysis result decision request message of specific field, and obtains the system domain name of service side;
If request message is for obtaining get request message, then start to record the binary data in 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 sent to service side by connection, and when receiving the response message of service side, the binary data of recording responses message, and be back to called side;
If request message is for issuing post request message, then open the local connection to service side according to the system domain name of service side, start to record the binary data in post request message, and circulation reading is carried out to post request message, service side is sent to successively by connecting by recording complete data division, and when receiving the response message that service side returns, the binary data of recording responses message, and circulation reading is carried out to response message, send to called side successively by recording complete data division.
Optionally, record cell specifically for:
The binary data including request message and response message of record is converted to character string, and therefrom parses the calling interface and calling device that adopt when called side is called service side;
Unserializing process is carried out to the string data obtained, obtains java applet exercisable tested object, and therefrom parse use when called side is called service side enter to join list, and service side return call result;
By the calling interface of acquisition, call method, enter to join list and call result to be defined as code elements information.
Optionally, generation unit specifically for:
According to the calling interface that the called side obtained uses, the calling interface title used in configuration testing code and calling interface type, and according to the calling device that called side uses, the calling device title used in configuration testing code, calling device type and call parameters;
Enter to join that list and service side return calls the tested object that result generates and resolve respectively to what use based on called side, acquisition enters to join title accordingly, enters to join type, enters to join assignment and result parameter title, result parameter type, result parameter assignment, and generates corresponding test code according to the information of acquisition.
Optionally, generation unit is further used for:
Entering to join that list and service side return calls the tested object that result generates and carry out in the process of Parameter analysis of electrochemical to what use based on called side, if tested object to be obtained is plain objects, then directly call; If tested object to be obtained is complex object, then reads file corresponding to complex object and preserve address to obtain the preservation file generated based on complex object, and be call again after complex object by preservation file transform.
In sum, in the embodiment of the present application, TCP agent system carries out binary data record to transmission data in data transmission procedure, again unserializing operation is carried out to the binary data of record, obtain code elements information, and based on the test code needed for the generation of code elements information, like this, can based on the corresponding test code of real Application of Interface environment generation, thus effectively improve the formation efficiency of test code, improve validity and the accuracy of test result, also greatly save the development and maintenance cost of test code simultaneously.Further, the versatility of the embodiment of the present application is high, is applicable to various protocol interface, and simple to operate, does not need developer to have development Experience for many years, thus enters one and reduce its expansion cost.
Those skilled in the art should understand, the embodiment of the application can be provided as method, system or computer program.Therefore, the application can adopt the form of complete hardware embodiment, completely software implementation or the embodiment in conjunction with software and hardware aspect.And the application can adopt in one or more form wherein including the upper computer program implemented of computer-usable storage medium (including but not limited to magnetic disk memory, CD-ROM, optical memory etc.) of computer usable program code.
The application describes with reference to according to the process flow diagram of the method for the embodiment of the present application, equipment (system) and computer program and/or block scheme.Should understand can by the combination of the flow process in each flow process in computer program instructions realization flow figure and/or block scheme and/or square frame and process flow diagram and/or block scheme and/or square frame.These computer program instructions can being provided to the processor of multi-purpose computer, special purpose computer, Embedded Processor or other programmable data processing device to produce a machine, making the instruction performed by the processor of computing machine or other programmable data processing device produce device for realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be stored in can in the computer-readable memory that works in a specific way of vectoring computer or other programmable data processing device, the instruction making to be stored in this computer-readable memory produces the manufacture comprising command device, and this command device realizes the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be loaded in computing machine or other programmable data processing device, make on computing machine or other programmable devices, to perform sequence of operations step to produce computer implemented process, thus the instruction performed on computing machine or other programmable devices is provided for the step realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
Although described the preferred embodiment of the application, those skilled in the art once obtain the basic creative concept of cicada, then can make other change and amendment to these embodiments.So claims are intended to be interpreted as comprising preferred embodiment and falling into all changes and the amendment of the application's scope.
Obviously, those skilled in the art can carry out various change and modification to the embodiment of the present application and not depart from the spirit and scope of the embodiment of the present application.Like this, if these amendments of the embodiment of the present application and modification belong within the scope of the application's claim and equivalent technologies thereof, then the application is also intended to comprise these change and modification.