Summary of the invention
In view of this, main purpose of the present invention is to provide a kind of Web method of testing and device, with solve network test method script in the prior art write complexity, test speed limited, can't simulate big pressure test, the problem bad to test environment adaptability.
For achieving the above object, technical scheme of the present invention is achieved in that
The invention provides a kind of Web method of testing, comprising:
Call the test case of required execution;
Send request msg according to the test case of being called to Web server;
Response data to institute's reception Web server is analyzed the generation final testing result.
The described test case of calling required execution specifically comprises:
The test case that is used for the Web test by XML (extensible Markup Language) (XML, Extensible Markup Language) configuration;
Described test case is stored;
From the test case of being stored, call the test case of required execution.
Describedly send request msg to Web server, specifically comprise according to the test case of being called:
The test case of being called resolved obtain test environment, test event, testing process and result and judge item;
Select the test event of required execution according to described testing process;
Send request msg according to selected test event to Web server.
Describedly send request msg to Web server, specifically comprise according to selected test event:
Generate at least one simulant-client according to the test pressure value in the selected test event;
According to the Internet protocol IP address of Web server in the described test environment and HTML (Hypertext Markup Language) (HTTP, the Hyper Text Transfer Protocol) link between port information foundation and the described Web server;
According to the link of setting up, and pass through the simulant-client that generated and send request msg in the selected test event to described Web server.
Described response data to institute's reception Web server is analyzed the generation final testing result, specifically comprises:
Judge that Web server that simulant-client receives executes whether the response data that testing process returns is normal response;
If normal response then judges that with described response data and result item compares the generation test result; If abnormal responses, the test case that then will receive the simulant-client of described abnormal responses data stops;
Judge whether performed test case finishes the test pressure value,, then generate final testing result if finish; If do not finish, then repeat described test case, up to finishing described test pressure value, and generate final testing result;
Write down described final testing result.
Describedly judge that whether response data is normal response, specifically comprises: judge according to the answer code that carries in the described response data whether described response data is normal response.
Described response data and result are judged compare the generation test result, specifically comprise:
Described response data and result are judged that item compares, and judges whether described response data is correct;
If correct, then generate correct test result; Otherwise, the test result of generation error.
Described method further comprises: if the test case of being called is a plurality of, then after the test case of current execution is finished the test pressure value, just carry out next test case.
The present invention also provides a kind of Web testing apparatus, comprising: test case calling module, request msg sending module, response data receiver module and data analysis module, wherein,
Described test case calling module, the test case that is used to call required execution offers the described request data transmission blocks;
The described request data transmission blocks is used for sending request msg according to the test case of being called to Web server;
Described response data receiver module connects the described request data transmission blocks, is used to receive the response data of Web server and offers described data analysis module;
Described data analysis module is used for the response data that is received is analyzed the generation final testing result.
Described test case calling module comprises that test case disposes submodule, test case sub module stored and test case and calls submodule, wherein,
Described test case configuration submodule is used for disposing the test case that is used for the Web test by XML and offers described test case sub module stored;
Described test case sub module stored is used for described test case is stored;
Described test case is called submodule, is used for calling the test case of required execution from the test case of storage.
The described request data transmission blocks comprises that test case analyzing sub-module, simulant-client generate submodule, submodule is set up in link and request msg sends submodule, wherein,
Described test case analyzing sub-module is used for the test case of being called resolved and obtains test environment, test event, testing process and result and judge that item offers that described simulant-client generates submodule, submodule is set up in link and request msg sends submodule;
Described simulant-client generates submodule, is used for generating at least one simulant-client according to the test pressure value of described test event;
Submodule is set up in described link, be used for according to the IP address of described test environment Web server and port information set up with described Web server between HTTP link;
The described request data send submodule, are used for according to the link of setting up, and pass through the simulant-client that generated and send request msg in the described test event to described Web server.
Described data analysis module comprises: response data judges that submodule, test result generate submodule, force value is judged submodule and outcome record submodule, wherein,
Described response data is judged submodule, is used to judge whether the response data that Web server that simulant-client receives execution testing process returns is normal response, if normal response then offers judged result described test result and generates submodule;
Described test result generates submodule, is used for normal response data and result are judged that item compares the generation test result, and notifies described force value to judge submodule;
Described force value is judged submodule, is used to judge whether performed test case finishes the test pressure value;
Described outcome record submodule, when being used for described test case and finishing the test pressure value, the final testing result that record generates.
Web method of testing provided by the invention and device utilize XML configuration Web test case, and by the test operation of parsing test case execution to the Web page, and the Web that can be provided with in conjunction with multithreading realization pressure tests.Web method test case configuration of the present invention is simple, test speed is fast, can simulate big pressure test, test environment is had adaptability better.
Embodiment
The technical solution of the present invention is further elaborated below in conjunction with the drawings and specific embodiments.
As shown in Figure 1, Fig. 1 is the flow chart of a kind of Web method of testing of the present invention, and this method mainly may further comprise the steps:
Step 101, test lead are called the test case of required execution.
The user can utilize XML to write to be used for the test case that the Web page is tested according to actual needs, and test case is at least one.Comprise in the test case: test environment, test event, testing process and result judge information such as item.Comprise information such as Internet protocol (IP, the Internet Protocol) address of Web server and port numbers in the test environment.Comprise the sequence numbering of this test event, the Web page of needs test, the information such as type, request msg and test pressure value of HTTP request in the test event.Test event is at least one, if test event is a plurality of, then each test event all has corresponding sequence numbering, and a plurality of test events are carried out in a certain order and promptly constituted so-called testing process.The result judges that item is to be used for the result of test event is judged, corresponding at least one result of test event judges item, each result judge item all corresponding need the sequence numbering of next test event of carrying out, hence one can see that, testing process is judged by the result and is decided.
The test case of writing is stored in the test lead with the form of file, and in the time of need carrying out the Web test, the user selects the test case of required execution on test lead, then by test lead selected test case of invoke user from the test case of storage.
Step 102, test lead sends request msg according to the test case of being called to Web server.
Test lead is resolved the test case of being called, and obtains test environment, test event, testing process and result and judges item.If it is a plurality of resolving the test event that obtains, then determined the execution sequence of these test events in the testing process, test lead selects test event to carry out successively according to testing process.
Concrete implementation to each test event is: test lead is selected the test event of required execution according to testing process, start thread pool then and create at least one thread according to the test pressure value in the selected test event, generate simulant-client according to the thread of creating again, a thread is responsible for carrying out the test operation of a simulant-client, and each simulant-client of generation all includes transmit control device and receives controller; In the test environment that test lead also needs to obtain according to parsing the IP address of Web server and port information set up with Web server between HTTP link; The simulant-client that generates is according to the link of setting up, and sends request msg in the selected test event by transmit control device to Web server.
Step 103, test lead is analyzed the generation final testing result to the response data of institute's reception Web server.
Web server is carried out corresponding test event according to the request msg that the simulant-client that receives test lead sends, and returns the response data of corresponding test event to simulant-client.Test lead receives the response data of corresponding test event by the reception controller of simulant-client, and judges whether to be normal response according to the answer code of response data.Defined following conditional code among the HTTP:
1XX: Temporary Response, the expression request msg is just processed;
2XX: success response, the expression request msg is successfully received, understands fully and is accepted;
3XX: redirect response, expression need take further operation to finish the processing of request msg;
4XX: the client computer mistake comprises the request msg that syntax error message or Web server can't be finished in the expression request msg;
5XX: server error, the expression Web server can't be finished request msg and handle;
6XX: global fault, represent that any Web server all can't finish request msg and handle.
1XX, 2XX, 3XX represent normal response in the above-mentioned conditional code, and 4XX, 5XX, 6XX represent abnormal responses.If test lead judges that the response data of corresponding test event that simulant-client receives is a normal response, then this response data is judged that with the result of corresponding test event item compares, find the result who conforms to this response data to judge item, forward this result then to and judge that a pairing test event continues to carry out testing process; If test lead judges that the response data of the corresponding test event that receives is an abnormal responses, then finish the testing process of this simulant-client.
Test lead all carries out above-mentioned analysis operation to the response data of carrying out each test event and returning, after test event is finished according to testing process, the response data of testing process is carries out the response data that last test event is returned in the testing process, the process that test lead is analyzed the response data of testing process specifically may further comprise the steps as shown in Figure 2:
Step 201, the response data that test lead acceptance test flow performing finishes.
Step 202, test lead judges according to the answer code of response data whether the response data of testing process is normal response, if normal response then forwards step 203 to; Otherwise,forward step 204 to.
Step 203, the result of the response data of testing process and the last test event of carrying out judged compare, judge the response data of testing process judges with the result of the test event of last execution whether item conforms to, if conform to, judge that then this response data is correct,forward step 205 to; Otherwise,forward step 206 to.
Step 204, be defined as abnormal responses after, the test operation that will carry out the simulant-client of this testing process stops.
Step 205, determine that response data is correct after, generate correct result and record, execution instep 207 then.
Step 206, determine the response data mistake after, the result of generation error and record, the test operation that will carry out the simulant-client of this testing process then stops.
Step 207, the simulant-client quantity that test lead is carried out this test case according to being used to of generating judges whether performed test case finishes the test pressure value, if judge complete test pressure value, then generate final testing result and record,forward step 208 then to; Otherwise forward step 209 to.
Step 208, if also have other test cases to need to carry out, then test lead forwards next test case continuation execution to.
Step 209 repeats this test case, up to finishing the test pressure value, generates final result and record then.
Below in conjunction with the testing process schematic diagram of the embodiment of the invention shown in Figure 3, Web method of testing of the present invention is elaborated.Test lead has called the test case of required execution from the test case of storage, by test case is resolved, obtain testing process, test environment, test event, result and judge information such as item, wherein, test event comprises A, B, C, D, E, F, six test events of G, and testing process as shown in Figure 3.According to testing process, test lead is at first carried out test event A, test lead starts thread pool and creates at least one thread according to the test pressure value among the test event A, generate simulant-client according to the thread of creating again, for example: the test pressure value is 100, the quantity of thread is 10 in the thread pool, then test lead once can be created 10 threads at most, generate a simulant-client at each thread, then once can generate 10 simulant-clients at most, also promptly be subjected to Thread Count quantitative limitation in the thread pool, test lead need repeatedly be created thread and repeat test case and just can finish the test pressure value.Test lead according to the IP address of Web server in the test environment and port information set up with Web server between HTTP link and the request msg of simulant-client in Web server transmission test event A by generating.Web server is carried out test event A according to the request msg that the simulant-client that receives test lead sends, and returns the response data of test event A to simulant-client.Test lead is by the response data of the reception controller acceptance test project A of each simulant-client, and be judged as normal response according to the answer code of response data, result with this response data and test event A judges that item compares then, the result of test event A judges that item comprises a1 and a2, next test event of a1 correspondence is test event B, and next test event of a2 correspondence is test event C.According to comparing, response data conforms to a1, then forwards test event B to and continues to carry out, and the implementation of the implementation of test event B and test event A is similar, is not going to repeat.Carry out the response data of test event B and the result of test event B and judge that a b1 and b2 compare, next test event of b1 correspondence is test event D, and next test event of b2 correspondence is test event E.According to comparing, response data conforms to b2, then forwards test event E to and continues to carry out.After test event E executes, testing process also is finished thereupon, test lead judges that with the response data of test event E and the result of test event E an e1 compares, if both do not conform to, then show erroneous results, test lead misregistration result, and stop to carry out the test operation of the simulant-client of this testing process; If both conform to, show that then the result is correct, test lead writes down correct result.After 10 simulant-clients that generate all executed testing process, test lead judged whether test case finishes test pressure value 100, if finish, then generates final testing result and record, carries out next test case then; If do not finish, then create thread again and repeat above-mentioned test case, up to finishing the test pressure value, generate final testing result and record then.
For realizing the Web method of testing of the invention described above, the present invention also provides a kind of Web testing apparatus, as shown in Figure 4, this device comprises: testcase calling module 100, request msg sendingmodule 200, responsedata receiver module 300 and data analysis module 400.Wherein, testcase calling module 100, the test case that is used to call required execution offers request msg sending module 200.Request msg sendingmodule 200 connects testcase calling module 100, is used for sending request msg according to the test case of being called to Web server.Responsedata receiver module 300, connection request data transmission blocks 200 is used to receive the response data of Web server and offers data analysis module 400.Data analysis module 400, connection responsedata reception module 300 is used for the response data that is received is analyzed the generation final testing result.
Wherein, testcase calling module 100 comprises: testcase configuration submodule 110, test case sub module stored 120 and test case are called submodule 130.Testcase configuration submodule 110 is used for disposing the test case that is used for the Web test by XML and offers test case sub module stored 120.Test case sub module stored 120 connects testcase configuration submodule 110, is used for the test case of configuration is stored.Test case is calledsubmodule 130, connects test case sub module stored 120, is used for calling the test case of required execution from the test case of storage.
Wherein, request msg sendingmodule 200 comprises: test case analyzing sub-module 210, simulant-client generatesubmodule 220,submodule 230 is set up in link and request msg sends submodule 240.Test case analyzing sub-module 210 is used for the test case of being called resolved and obtains test environment, test event, testing process and result and judge that item offers that simulant-client generatessubmodule 220,submodule 230 is set up in link and request msg sends submodule 240.Simulant-client generatessubmodule 220, connects test case analyzing sub-module 210, is used for generating at least one simulant-client according to the test pressure value oftest event.Submodule 230 is set up in link, connects test case analyzing sub-module 210, be used for according to the IP address of test environment Web server and port information set up with Web server between HTTP link.Request msg sendssubmodule 240, connect test case analyzing sub-module 210, simulant-client generation submodule 220 and link and set upsubmodule 230, be used for according to the link of setting up, and pass through the simulant-client that generated and send request msg in the test event to Web server.
Wherein,data analysis module 400 comprises: response data judges that submodule 410, test result generatesubmodule 420, force value is judged submodule 430 and outcome record submodule 440.Response data is judged submodule 410, is used to judge that Web server that simulant-client receives executes whether the response data that testing process returns is normal response, if normal response then offers judged result test result generation submodule 420.Test result generatessubmodule 420, and the connection response data are judged submodule 410, be used for normal response data and result are judged that item compares the generation test result, and the notice force value is judged submodule 430.Force value is judged submodule 430, connects test result and generatessubmodule 420, is used to judge whether performed test case finishes the test pressure value.Outcome record submodule 440 connects that test result generatessubmodule 420 and force value is judged submodule 430, when being used for test case and finishing the test pressure value, and the final testing result that record generates.
The above is preferred embodiment of the present invention only, is not to be used to limit protection scope of the present invention.