Specific embodiment
In the following, the preferred embodiment of the present invention is described in detail with reference to the accompanying drawings.In the accompanying drawings, although being shown in different attached drawings
In, but identical appended drawing reference is for indicating identical or similar component.For clarity and conciseness, to known function and structure
Detailed description will be omitted, to avoid keeping subject of the present invention unclear.
Fig. 1 shows the schematic diagram of the interface test system of embodiment according to the present invention.As shown in fig. 1, the system
Cooperate the calling interface 120 for carrying out interface testing including tested interface 110, with tested interface 110 and will be detailed below retouching in detail
The network agent 130 stated.
In the embodiment shown in fig. 1, network agent 130 is connected between tested interface 110 and calling interface 120, and
Including interface testing tool 132 and protocol entity data modification unit 136.Protocol entity data modification unit 136 is used for from calling
The returned data that interface 120 returns to tested interface 110 is handled to generate test data.Interface testing tool 132 be used for
Tested interface 110 forwards test data generated, and observes and record tested processing of the interface 110 to test data.
As shown in fig. 1, the proper network of non-test purposes may be present between tested interface 110 and calling interface 120
Communication.The normal network communications can be without the network agent in the embodiment of the present invention.
However when testing, the data for test can be sent from tested interface 110 to calling interface 120, called
Interface 120 generates above-mentioned returned data when receiving the data.In some embodiments, it is connect from tested interface 110 to calling
Data meeting approach network agent (the interface testing tool 132 specifically, such as in network agent) that mouth 120 is sent, but network
130 (such as interface testing tools 132 therein) of agency do not modify to the data.And in further embodiments, due to
It is not necessary to modify data transmission can not also approach network agent 130.Fig. 1 shows latter situation, in order to make illustrative simplicity simultaneously
It can be readily appreciated that be not shown in Fig. 1 this for test transmission of the data from tested interface 110 to calling interface 120.
The processing of above-mentioned protocol entity data modification unit 136 includes modifying to agreement volume data, with data-driven
Mode carries out interface testing, i.e., by sending different data (for example, abnormal data) to tested interface 110 and observing tested interface
The properties of tested interface 110 are tested in the processing of 110 pairs of these different data.In test, interface 110 is tested as visitor
Family end can modify IP address and the port of destination service, to be configured to the IP address and port that testing tool 132 is monitored.This is repaired
Changing can be executed by tested interface place equipment, can also be executed by interface testing tool, or can be by other any relevant equipment
It executes, the present invention limits not to this.Furthermore here, without making any change to calling interface 120.
As it is known in the art, communication protocol (such as http) includes protocol header and protocol entity two parts, the former is usually
Guarantee that communication is normally carried out, the latter indicates specific Content of Communication.Therefore agreement volume data used herein is also sometimes referred to as
The data portion of agreement.
In some examples of the implementable embodiment of the present invention, such as website needs the data for calling third party to provide to connect
Mouthful, and transmitted by the way of json plaintext string in calling process.When testing website interface, need to exceeding
The data of critical value are tested, and third party's interface can not test data as arteface.This implementation can be used at this time
The method that example provides intercepts and captures clear data packet, and it directly can be revised as any number, relays to tested interface, observes quilt
Survey the process flow of interface.
Above-mentioned example transmits data by the way of json plaintext string, however in some other example, interface is logical
Letter does not use the TCP data of plaintext directly, but the various ways such as http agreement, snmp agreement, ssh agreement can be used, or
Labyrinth is serialized and is sent by person, constitutes proprietary protocol body.In consideration of it, as shown in Figure 1, network agent 130 further includes interface
Protocol analysis unit 134, for before modifying data to the agreement used between tested interface 110 and calling interface 120 into
Row parsing.
It is communicated since a network interface generallys use a kind of fixed protocol, need to configure is made before testing
Protocol architecture.Specifically, it for common protocol, is parsed according to inherent structure;For proprietary protocol, dynamically load first is assisted
Structural body is discussed, then unserializing is carried out to the protocol architecture body.Protocol architecture body generallys use " .h " file configuration, in test work
The agreement according to selected by user is when 130 operation of tool come dynamic call.
In some other embodiment of the invention, the backup of test scene and the regression test of interface can also be realized.
In these embodiments, as shown in Figure 1, network agent 130 may also include contextual data backup units 138, it is used for backup test
Scene.In the case, interface testing tool 132 can carry out automatic regression test using the test scene backed up.
Specifically, contextual data backup units 138 can back up at least one of following:
The returned data (can be used as the key value for Auto-matching message) received from calling interface 120
Agreement used in communication between tested interface 110 and calling interface 120
By protocol entity data modification unit 136 modify test data that returned data generates (may for multiple values,
The mode that json character string can be used stores)
In some instances, test data can also edit in advance.In the case, network agent 130 can shown in Fig. 1
Including configuration file (not shown).The numerical value needed to be traversed for can be stored in configuration file as test data.When holding repeatedly
When the communication of the same interface of row, interface testing tool 130 can exist the returned data that calling interface 120 returns as keyword
Corresponding test scene is selected in the test scene that contextual data backup units 138 back up and applies selected test scene,
And automatic sequence using the test number saved in configuration file as the test data forwarded to tested interface 110,
To realize the test of interface ergodic and Fuzz test.
Interface testing is executed by using above-mentioned network agent, tester can direct configuration surroundings, execute data and drive
Dynamic test.The program constructs interface data without more people's joint debuggings, has saved manpower and has improved efficiency.Using interface protocol
When resolution unit 134, the program also has stronger versatility, can on transport layer standard agreement and nonstandard protocol into
Row parses and constructs test data, to realize that interface protocol is tested.And in usage scenario data backup unit 138, after backup
Test scene repeatable execute, it is not necessary to test data is made in purchase again, saves manpower, improves regression test efficiency.
Above with reference to Fig. 1 describe embodiment according to the present invention interface test system and its used in network agent
Brief configuration.It should be noted that the brief configuration is merely to illustrate the solution of the present invention and the exemplary structure made,
The solution of the present invention is not limited to structure shown in FIG. 1.For example, there may also be other components and/or test to connect in the structure
Mouthful, such as Database Systems, redis system, zookeeper, other websevice.For example, each unit in the structure
It can be realized by more or fewer components, as interface protocol resolution unit 134 and protocol entity data modification unit 136 can
Realized in same component etc..Or even in some cases, interface protocol resolution unit 134, protocol entity data modification unit
One or more of 136 and contextual data backup units 138 can be incorporated into that interface testing tool 132.Interface testing work at this time
Tool 132 is equivalent to the network agent 130 in above-described embodiment.In some instances, interface protocol resolution unit 134, protocol entity
One or more of data modification unit 136 and contextual data backup units 138 can be by way of detachable modules simultaneously
Incoming interface testing tool 132.
The flow chart of the interface test method of embodiment according to the present invention is described below with reference to Fig. 2.Fig. 2 shows one
Outline flowchart of the kind for the method for test interface.This method is executed by above-mentioned network agent 130.
As shown in Fig. 2, in step 210, such as returned to from calling interface 120 by protocol entity data modification unit 136
The returned data of tested interface 110 is handled to generate test data.
In a step 220, such as from interface testing tool 132 to tested interface 110 test data generated is forwarded.
In step 230, such as by interface testing tool 132 tested interface 110 is observed and records to test data
Reason.
In some instances, include modifying to agreement volume data processing returns to data, in a manner of data-driven into
Line interface test.In test, tested interface 110 can modify IP address and the port of destination service as client, be matched
It is set to the IP address and port that testing tool 132 is monitored.Without making any change to calling interface 120.
As described above, in some instances, for example, in the case where interface communication does not use the TCP data of plaintext directly,
The agreement used between tested interface 110 and calling interface 120 can be parsed before modifying data.The parsing is by interface
Protocol analysis unit 134 is completed.Fig. 3 shows the example of the flow chart of the concrete operations of protocol analysis.
Specifically, in the step 310, the registration of new agreement is carried out.If the agreement to be selected is registered, which can be jumped
It crosses.Protocol registration process is to keep protocol architecture file and protocol name associated, so as to the subsequently selected agreement of tester.It connects
Mouth protocol analysis unit 134 can be loaded and be parsed automatically.
In step 320, the communication institute between tested interface 110 and calling interface 120 is being selected in the agreement registered
The agreement used.
In a step 330, judge whether selected agreement is common protocol.
If it is common protocol, in step 340, built-in inherent structure is called to carry out protocol analysis.
If not common protocol, then show that agreement is proprietary protocol, in step 350 dynamically load protocol architecture body.
As described above, protocol architecture body generallys use " .h " file configuration, dynamically load protocol architecture body includes reading " .h " file.
In step 360, to the agreement knot of dynamically load in the intrinsic protocol architecture or step 350 called in step 340
Structure body is parsed, and judges whether protocol analysis is normal in step 370.
If protocol analysis is abnormal, parsing mistake, protocol finishes parsing operation are prompted the user in step 380.With
Error handle can be carried out according to related procedure after family, such as reselect agreement or re-registration protocol.In step 380
In, can by any one of sound, light, text importing or other prompting modes well-known to those skilled in the art or its
To prompt user, the present invention limits not to this for combination.
If protocol analysis is normal, the data content after parsing is shown, in step 390 with protocol entity for users to use
Data modification unit 136 modifies data, and same protocol finishes parsing.
Using some other embodiment of the invention, the backup of test scene and the regression test of interface can also be realized.
The contextual data backup units 138 of test scene backup as shown in Figure 1 are completed.Specifically, contextual data backup units 138 can be standby
At least one of part or less:
The returned data (can be used as the key value for Auto-matching message) received from calling interface 120
Agreement used in communication between tested interface 110 and calling interface 120
By protocol entity data modification unit 136 modify test data that returned data generates (may for multiple values,
The mode that json character string can be used stores)
In some instances, test data can also edit in advance.In the case, network agent 130 can shown in Fig. 1
Including configuration file (not shown).The numerical value needed to be traversed for can be stored in configuration file as test data.When holding repeatedly
When the communication of the same interface of row, interface testing tool 130 can exist the returned data that calling interface 120 returns as keyword
Corresponding test scene is selected in the test scene that contextual data backup units 138 back up and applies selected test scene,
And automatic sequence using the test number saved in configuration file as the test data forwarded to tested interface 110,
To realize the test of interface ergodic and Fuzz test.
The test scene backed up can be by interface testing tool 132 using carrying out automatic regression test.Fig. 4 shows root
According to the exemplary process diagram of the automatic regression test method of the embodiment of the present invention.
As shown in figure 4, setup test environment is arranged if configured test interface 110 and calling interface 120 in step 410
Used agreement etc..
At step 420, it executes interface to call, grabs the returned data returned from calling interface 120.
In step 430, when transmitting data using ciphertext mode, used agreement is transmitted to data and is solved
Analysis.
Judge whether to execute automatic test in step 440
If do not executed, method and step proceeds to step 450, display protocol structure and data content, and in step 460
Data content is modified to generate test data by protocol entity data modification unit by user.In step 470, to tested interface
110 send test data, and optionally backup test scene.Then, method goes to step 420 and continues to execute, until test knot
Beam.
Automatic test is executed if determined at step 440, in step 480, is surveyed according to the content recognition in data packet
Examination hall scape.Specifically, the returned data that calling interface 120 can be returned is as keyword in scene data backup unit 138
Corresponding test scene is selected in the test scene of backup and applies selected checkout area.
Next, obtaining test data in step 490.For example, can be sequentially using the test saved in configuration file
Numerical value is as test data.Or in some instances, can be used that contextual data backup units 138 back up with identify
The corresponding test data of test scene is as acquired test data.
In step 495, modifies the data packet of test data and send test data to tested interface 110.Specifically, it repairs
Change the data content of data packet.For example, abnormal data can be revised as data content, such as negative, decimal, null value, unreasonable number
According to etc..Modifying content can be depending on specific test purpose.The modification can be as user interface provided by network agent
It is manually performed at (not shown), or by calling pre-set program/code to execute automatically, the present invention limits not to this
System.
By modifying the data packet of test data, issuable any abnormal conditions at analog calling interface, thus
Processing/reaction of the abnormal conditions can survey the properties of tested interface by observing and recording tested interface
Examination.
Then, method goes to step 420 and continues to execute, until test terminates.
Above description is only used for realizing embodiments of the present invention, and it should be appreciated by those skilled in the art do not taking off
Any modification or partial replacement from the scope of the present invention, the range that should belong to claim of the invention to limit, because
This, the scope of protection of the invention shall be subject to the scope of protection specified in the patent claim.