Embodiment
Below, the preferred embodiment of the present invention is described in detail with reference to accompanying drawing.In the accompanying drawings, although be shown in different accompanying drawings, identical Reference numeral is for representing identical or similar assembly.For clarity and conciseness, will be omitted the detailed description of known function and structure, to avoid making theme of the present invention unclear.
Fig. 1 shows the schematic diagram of interface test system according to an embodiment of the invention.As shown in fig. 1, this system comprises tested interface 110, coordinates the calling interface 120 and network agent to be described in detail below 130 that carry out interface testing with tested interface 110.
In the embodiment shown in fig. 1, network agent 130 is connected between tested interface 110 and calling interface 120, and comprises interface testing instrument 132 and protocol entity data modification unit 136.Protocol entity data modification unit 136 is for processing to generate test data to the return data returning tested interface 110 from calling interface 120.The process of tested interface 110 pairs of test datas is observed and recorded to interface testing instrument 132 for forwarding the test data generated to tested interface 110, and.
As shown in fig. 1, the normal network communications of non-test purposes can be there is between tested interface 110 and calling interface 120.This normal network communications can without the network agent in the embodiment of the present invention.
But when testing, the data for testing being sent from tested interface 110 to calling interface 120, when calling interface 120 receives these data, producing above-mentioned return data.In certain embodiments, the data meeting approach network agent sent from tested interface 110 to calling interface 120 (particularly, such as, interface testing instrument 132 in network agent), but network agent 130 (such as interface testing instrument 132) is not wherein modified to these data.And in further embodiments, due to without the need to amendment, these data send also can not approach network agent 130.Fig. 1 shows latter event, and in order to make illustrative simplicity and easy to understand, in Fig. 1, the not shown data that this is used for testing are from tested interface 110 to the transmission of calling interface 120.
The process of above-mentioned protocol entity data modification unit 136 comprises modifies to protocol entity data, interface testing is carried out in the mode of data-driven, namely by sending different pieces of information (such as, abnormal data) to tested interface 110 and observing tested interface 110 to the process of these different pieces of informations to test the properties of tested interface 110.When testing, tested interface 110 can the IP address of modifying target service and port as client, to be configured to IP address that testing tool 132 monitors and port.This amendment can be performed by tested interface place equipment, also can be performed by interface testing instrument, or can be performed by other any relevant equipment, and the present invention does not limit this.This external this, without the need to making any change to calling interface 120.
As known in the art, communication protocol (as http etc.) comprises protocol header and protocol entity two parts, and the former ensures that communication is normally carried out usually, and the latter represents concrete Content of Communication.Therefore protocol entity data used herein are also sometimes referred to as the data division of agreement.
In some examples can implementing the embodiment of the present invention, such as website needs to call the data-interface that third party provides, and adopts the mode of json expressly character string to transmit in invoked procedure.When testing website interface, need the data to exceeding critical value to test, and third party's interface cannot the such test data of arteface.The method that the present embodiment now can be adopted to provide intercepts and captures clear data bag, and it directly can be revised as any number, then is transmitted to tested interface, observes the handling process of tested interface.
Above-mentioned example adopts the mode of json plaintext character string to transmit data, but in some other example, interface communication does not directly use tcp data expressly, but the various ways such as http agreement, snmp agreement, ssh agreement can be adopted, or labyrinth serializing is sent, forms proprietary protocol body.Given this, as shown in Figure 1, network agent 130 also comprises interface protocol resolution unit 134, for resolving the agreement used between tested interface 110 and calling interface 120 before Update Table.
Because a network interface adopts a kind of fixed protocol to communicate usually, therefore need before testing to configure the protocol architecture used.Particularly, for common protocol, resolve according to inherent structure; For proprietary protocol, first dynamic load protocol architecture body, then unserializing is carried out to this protocol architecture body.Protocol architecture body adopts " .h " file configuration usually, can carry out dynamic call when testing tool 130 runs according to user-selected agreement.
In some other embodiment of the present 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 also can comprise contextual data backup units 138, for backup test scene.In the case, interface testing instrument 132 can utilize backed up test scene to carry out automatic regression test.
Particularly, contextual data backup units 138 can back up following at least one item:
From the return data (can be used as the key value for Auto-matching message) that calling interface 120 receives
The agreement that communication between tested interface 110 and calling interface 120 uses
Return data is revised and the test data (may for multiple value, the mode of json character string can be adopted to store) that generates by protocol entity data modification unit 136
In some instances, test data also can be edited in advance.In the case, the network agent 130 shown in Fig. 1 can comprise configuration file (not shown).Can be kept at needing the numerical value of traversal in configuration file as test data.When repeatedly performing the communication of same interface, corresponding test scene is selected and test scene selected by application in the test scene that the return data that calling interface 120 can return by interface testing instrument 130 backs up as keyword at scene data backup unit 138, and automatic sequence ground uses the test number of preserving in configuration file to be used as the test data forwarded to tested interface 110, to realize the test of interface ergodic and Fuzz test.
By using the test of above-mentioned network agent executive's interface, tester can direct configuration surroundings, the test of execution data-driven.The program, without the need to many people uniting and adjustment structure interface data, has been saved manpower and has improved efficiency.When using interface protocol resolution unit 134, the program also has stronger versatility, can resolve the standard agreement on transport layer and nonstandard protocol and construct test data, to realize interface protocol test.And when use scenes data backup unit 138, the test scene after backup can repeat, again need not purchase and make test data, save manpower, improve regression test efficiency.
The brief configuration of network agent that above reference diagram 1 describes interface test system according to an embodiment of the invention and wherein uses.It should be noted that this brief configuration is only the example arrangement made to set forth the solution of the present invention, the solution of the present invention is not limited to the structure shown in Fig. 1.Such as, other assembly and/or test interface in this structure, can also be there is, as Database Systems, redis system, zookeeper, other websevice etc.Such as, the unit in this structure also can be realized by more or less assembly, as interface protocol resolution unit 134 and protocol entity data modification unit 136 can realize in same assembly.Or even in some cases, one or more in interface protocol resolution unit 134, protocol entity data modification unit 136 and contextual data backup units 138 are merged in interface testing instrument 132.Now interface testing instrument 132 is equivalent to the network agent 130 in above-described embodiment.In some instances, one or more in interface protocol resolution unit 134, protocol entity data modification unit 136 and contextual data backup units 138 can be incorporated to interface testing instrument 132 by the mode of detachable module.
The flow chart of interface test method is according to an embodiment of the invention described below with reference to Fig. 2.Fig. 2 shows a kind of outline flowchart of the method for test interface.The method is performed by above-mentioned network agent 130.
As shown in Figure 2, in step 210, such as processed to generate test data to the return data returning tested interface 110 from calling interface 120 by protocol entity data modification unit 136.
In a step 220, such as generated test data is forwarded by interface testing instrument 132 to tested interface 110.
In step 230, such as observed and recorded the process of tested interface 110 pairs of test datas by interface testing instrument 132.
In some instances, process return data comprises modifies to protocol entity data, carries out interface testing in the mode of data-driven.When testing, tested interface 110 can the IP address of modifying target service and port as client, is configured as IP address and port that testing tool 132 monitors.Without the need to making any change to calling interface 120.
As mentioned above, in some instances, such as, when interface communication does not directly use tcp data expressly, can the agreement used between tested interface 110 and calling interface 120 be resolved before Update Table.This parsing is completed by interface protocol resolution unit 134.Fig. 3 shows the example of the flow chart of the concrete operations of protocol analysis.
Particularly, in the step 310, the registration of New Deal is carried out.If the agreement selected is registered, this step can skip.Protocol registration process is that protocol architecture file and protocol name are associated, so that this agreement of the follow-up selection of tester.Interface protocol resolution unit 134 can automatically load and resolve.
In step 320, the agreement selecting the communication between tested interface 110 and calling interface 120 to use in registered agreement.
In a step 330, whether the agreement selected by judgement is common protocol.
If common protocol, in step 340, call built-in inherent structure and carry out protocol analysis.
If not common protocol, then show that agreement is proprietary protocol, in step 350 dynamic load protocol architecture body.As mentioned above, protocol architecture body adopts " .h " file configuration usually, and dynamic load protocol architecture body comprises reading " .h " file.
In step 360, the protocol architecture body of dynamic load in the intrinsic protocol architecture called in step 340 or step 350 is resolved, and judges that whether protocol analysis is normal in step 370.
If protocol analysis is abnormal, point out parse error to user in step 380, protocol finishes parse operation.Error handle can be carried out according to related procedure, as reselected agreement or re-registration protocol etc. after user.In step 380, point out user by any one in sound, light, text importing or other prompting modes well-known to those skilled in the art or its combination, the present invention does not limit this.
If protocol analysis is normal, then in step 390, shows the data content after resolving, use protocol entity data modification unit 136 Update Table for user, and same protocol finishes is resolved.
Utilize some other embodiment of the present invention, the backup of test scene and the regression test of interface can also be realized.Test scene backup contextual data backup units 138 as shown in Figure 1 completes.Particularly, contextual data backup units 138 can back up following at least one item:
From the return data (can be used as the key value for Auto-matching message) that calling interface 120 receives
The agreement that communication between tested interface 110 and calling interface 120 uses
Return data is revised and the test data (may for multiple value, the mode of json character string can be adopted to store) that generates by protocol entity data modification unit 136
In some instances, test data also can be edited in advance.In the case, the network agent 130 shown in Fig. 1 can comprise configuration file (not shown).Can be kept at needing the numerical value of traversal in configuration file as test data.When repeatedly performing the communication of same interface, corresponding test scene is selected and test scene selected by application in the test scene that the return data that calling interface 120 can return by interface testing instrument 130 backs up as keyword at scene data backup unit 138, and automatic sequence ground uses the test number of preserving in configuration file to be used 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 made for carrying out automatic regression test by interface testing instrument 132.Fig. 4 shows the exemplary process diagram of automatic regression test method according to an embodiment of the invention.
As shown in Figure 4, setup test environment in step 410, as configuration testing interface 110 and calling interface 120, arranges used agreement etc.
At step 420 which, executive's interface calls, and captures the return data returned from calling interface 120.
In step 430, when adopting ciphertext mode to transmit data, the agreement that transfer of data uses is resolved.
Judge whether in step 440 to perform automatic test
If do not performed, method step proceeds to step 450, display protocol structure and data content, and passes through protocol entity data modification unit Update Table content to produce test data by user in step 460.In step 470, send test data to tested interface 110, and backup test scene alternatively.Then, method forwards step 420 to and continues to perform, until test terminates.
If determine to perform automatic test in step 440 place, in step 480, according to the content recognition test scene in packet.Particularly, corresponding test scene is selected in the test scene that the return data that calling interface 120 can be returned backs up as keyword at scene data backup unit 138 and checkout area selected by application.
Next, in step 490, test data is obtained.Such as, the test number of preserving in configuration file can be sequentially used to be used as test data.Or in some instances, can use scenes data backup unit 138 back up the test data corresponding with the test scene identified be used as obtained test data.
In step 495, revise the packet of test data and send test data to tested interface 110.Particularly, the data content of Update Table bag.Such as, data content can be revised as abnormal data, as negative, decimal, null value, unreasonable data etc.Revised context can be determined according to concrete test purpose.This amendment manually can be performed at the interface (not shown) that network agent provides by user, or automatically performs by calling the program/code pre-set, and the present invention does not limit this.
By revising the packet of test data, the issuable any abnormal conditions in calling interface place can be simulated, test by observing and recording the properties of process/reaction to tested interface of tested interface to these abnormal conditions thus.
Then, method forwards step 420 to and continues to perform, until test terminates.
Description is above only for realizing embodiments of the present invention; it should be appreciated by those skilled in the art; the any modification or partial replacement do not departed from the scope of the present invention; the scope that all should belong to claim of the present invention to limit; therefore, protection scope of the present invention should be as the criterion with the protection range of claims.