A kind of automatic interface testing method and its system
Technical field
The embodiment of the present invention belongs to software testing technology field, more particularly to a kind of automatic interface testing method and its is
System.
Background technology
Web interface is the mode that server is interacted with client, i.e. browser or other client utilitys and web services
The UI layers of agreement of interaction;Web interface automated testing method is one kind of station automatic test on UI layers of web services program
Means of testing, generally requires constantly to search URL (Uniform in conventional interface automatic test
Resource Locator, URL), backstage returned data is then waited, operating process is complicated, and the stand-by period is more long, reduces survey
Examination efficiency, influences the automation cycle, while also increasing the workload of tester and developer.
Therefore, in view of the shortcomings of the prior art, it is necessary to propose a kind of new automatic interface testing method.
The content of the invention
The embodiment of the invention provides a kind of automatic interface testing method and its system, it is intended to solve existing interface certainly
In dynamicization method of testing, test process is cumbersome, and the backstage response stand-by period is long, causes tester and developer's workload
Greatly, the low problem of testing efficiency.
A kind of embodiment of the present invention first aspect, there is provided automatic interface testing method, it is characterised in that methods described
Including:
Test case is received, corresponding test case interface is opened according to the test case;
The uniform resource position mark URL of test case interface described in template file is called, with by the test case
The URL at interface sends test request to server;
After server responds the test request, it be not empty test request to call interface function registered in advance parses
The server response results, draw actual check value;
Compare the actual check value and expected check value, the test result of test case is drawn according to comparative result.
A kind of second aspect of the embodiment of the present invention, there is provided interface automatization test system, the interface automatic test
System includes:
Interface opening unit, for receiving test case, corresponding test case interface is opened according to the test case;
Test request transmitting element, the URL for calling test case interface described in template file
URL, test request to server is sent with by the URL at the test case interface;
Actual check value determining unit, for after server responds the test request, calling interface registered in advance
Function parsing is not the response results of the server of empty test request, draws actual check value;
Test result determining unit, for comparing the actual check value and expected check value, draws according to comparative result
The test result of test case.
In embodiments of the present invention, according to the test case for receiving, corresponding test case interface is opened, by searching
The URL at test case interface in template file, sends page test request, after server responds the test request, calls and connects
The response results analysis of mouth function pair draws actual check value, and relatively actual check value and expected check value draw test result.This
During inventive embodiments are tested test case, the URL, Ran Houfa of test case are directly searched from template file
Send test to instruct, the follow-up test process to test case is completed by interface function, it is to avoid wait backstage after searching URL repeatedly
The process of data response.The workload of tester and developer is reduced simultaneously, improves testing efficiency.
Brief description of the drawings
Fig. 1 is a kind of flow chart of automatic interface testing method that first embodiment of the invention is provided;
Fig. 2 is a kind of structure chart of interface automatization test system that second embodiment of the invention is provided.
Specific embodiment
In order to make the purpose , technical scheme and advantage of the present invention be clearer, it is right below in conjunction with drawings and Examples
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.
In the embodiment of the present invention, the corresponding test case page is opened according to test case first, called from template file
The URL at test case interface, and send test request to server from the test case interface;Server pair
After the test case for receiving is tested, calling interface function pair test result is analyzed, and obtains the reality of test case
Check value, described actual check value is compared with expected check value, you can obtain test result.
In order to illustrate technical solutions according to the invention, illustrated below by specific embodiment.
Embodiment one:
Fig. 1 shows a kind of flow chart of automatic interface testing method that first embodiment of the invention is provided, and describes in detail such as
Under:
Step S11, receives test case, and corresponding test case interface is opened according to the test case;
In the step, after receiving test case, the test case correspondence is opened by different way according to test case
Test case interface;Specifically:Test case is judged first, test case may relate to user role information,
Therefore, first determine whether whether received test case is related to user profile, then calling interface, beats in different ways
Open test case interface.
Preferably, the reception test case, corresponding test case interface, specific bag are opened according to the test case
Include:
Test case is received, judges the test case whether comprising user profile;
According to judged result calling interface, corresponding test case interface is opened by different way.
Preferably, when the test case includes user profile, the test case is directly opened, into test case
Interface;
When the test case does not include user profile, after removing the cookie information that interface is carried, test is entered back into
Use-case interface.
Specifically, judge whether the test case for receiving is related to user role information, when test case is related to use
During the information of family, the interface that testing tool is provided carries cookie information in itself, can directly open test case band and have permission limitation
URL (Uniform Resource Locator, URL), into test case interface, it is not necessary to step on again
Record.After judging that test case is not related to user role information, interface to remove self-contained cookie information automatically, beat again
The URL that band has permission limitation is opened, homepage or login page that then page jump is limited to lack of competence log into test case
Interface.
Step S12, calls the uniform resource position mark URL at the test case interface, with by test case circle
The URL in face sends test request to server;
URL is a kind of succinct expression of the position and access method to the resource that can be obtained from internet, is mutual
The address of standard resource in networking.Each file on internet has a unique URL, and the information that it is included points out file
Position and browser how should process it.In the step, the URL at test case interface is called from template file, looked into
Test case position and the data resource for being included are looked for, then directly test request to server is sent from test case interface.
Preferably, the uniform resource position mark URL at the test case interface is being called, with by test case circle
The URL in face sends test request to before server, also includes:
URL, test data and the expected check value at the test case interface are extracted, and is stored.
Specifically, the URL at test case interface, the test data that test case interface is included are extracted in advance, and are set
The expected check value of test case verification, above- mentioned information is stored in fixed template file, and template file is numbered,
So that it is corresponded with test case.Because each test case has unique corresponding template file, and template is literary
Part stores URL, test data and the expected check value that test case interface is included again, therefore is tested to test case
When, the to be tested data that include can be quickly found out in test case URL and test case according to template file, simplify URL's
Invoked procedure is found, the testing time has been saved;Meanwhile, also can quickly find correspondence when subsequently needing to call expected check value
Expected check value, further improve testing efficiency.
Step S13, after server responds the test request, it be not sky to call interface function registered in advance parses
The response results of the server of test request, draw actual check value;
In the step, after test request is received, the data to be tested included in detection test request are server
No is sky, is not space-time in data to be tested, responds the test request, returns to JSON corresponding with testing data
(JavaScript Object Notation) formatted data.Interface function registered in advance receives the JSON formatted datas,
It is parsed.The actual check value of test case is drawn according to analysis result.
Further, it is space-time in the test request, obtains the HTML html at test case interface, root
Checkpoint, and back-checking result are verified according to test case.The test request is empty to refer to that what is included in the test request treats
It is sky to survey data.
Step S14, relatively more described actual check value and expected check value, the test of test case is drawn according to comparative result
As a result.
In the step, JSON formatted datas are parsed in interface function, after obtaining the actual check value of test case,
Call the expected check value corresponding with test case being stored in advance in template file, relatively more described actual check value with it is described
Expected check value;When the actual check value is identical with the expected check value, test case runs succeeded;If the two is not
Together, then test case performs failure.
Preferably, in the actual check value and expected check value, the survey of test case is drawn according to comparative result
After test result, also include:
The synchronous storage test result sends the test result to specified address under fixation catalogue.
After all use-case end of runs, under operation result automatic synchronization to fixed catalogue, according to STMP (Simple
Mail Transfer Protocol) agreement sends test report to specified address, and so that user checks, the specified address can be with
To specify the address of mailbox, or specify receiving terminal.
In first embodiment of the invention, when test case is received, first it is judged, according to test case whether
Comprising user role information, calling interface opens test case interface in different ways.Test is called to use from template file
The URL at example interface, test request is sent to server, after server responds the test request, calling interface function parsing clothes
The response results of business device, while returning to actual check value, relatively actual check value draws the survey of test case with expected check value
Test result.Test case URL, test data and expected check value are directly called in the present embodiment from template file, it is not necessary to
User carries out the logical operation of complexity in client, while reducing tester and developer's workload, improves test
Accuracy rate and testing efficiency.
It should be understood that in embodiments of the present invention, the size of the sequence number of above-mentioned each process is not meant to the elder generation of execution sequence
Afterwards, the execution sequence of each process should be with its function and internal logic determination, the implementation process structure without tackling the embodiment of the present invention
Into any restriction.
Embodiment two:
Fig. 2 shows a kind of structure chart of interface automatization test system that second embodiment of the invention is provided, in order to just
In explanation, the part related to the embodiment of the present invention is illustrate only.The interface automatization test system includes:Open single in interface
Unit 21, test request transmitting element 22, actual check value determining unit 23, test result determining unit 24;Wherein:
Interface opening unit 21, for receiving test case, corresponding test case circle is opened according to the test case
Face;
After receiving test case, interface opening unit 21 is opened described by different way according to the difference of test case
The corresponding test case interface of test case;
Preferably, the interface opening unit 21, specifically includes:
Whether judge module, for receiving test case, judge the test case comprising user profile;
Interface opening module, for according to judged result calling interface, corresponding test case circle being opened by different way
Face.
Specifically:Test case is judged first by judge module, test case may relate to user role letter
Breath, therefore, first determine whether whether received test case is related to user profile, then tied according to judgement by interface opening module
Really, calling interface opens test case interface in different ways.
Preferably, when the test case includes user profile, the test case is directly opened, into test case
Interface;
When the test case does not include user profile, after removing the cookie information that interface is carried, test is entered back into
Use-case interface.
Specifically, judge whether the test case for receiving is related to user role information, when test case is related to use
During the information of family, the interface that testing tool is provided carries cookie information in itself, can directly open test case band and have permission limitation
URL, into test case interface, it is not necessary to log in again.When judging that test case is not related to user role information, interface from
After the self-contained cookie information of dynamic removing, the URL that band has permission limitation is again turned on, then page jump is limited to lack of competence
The homepage or login page of system, log into test case interface.
Test request transmitting element 22, the URL for calling test case interface described in template file
URL, test request to server is sent with by the URL at the test case interface;
Each file on internet has a unique URL, and the information that it is included points out the position of file and clear
How device of looking at should process it.In the step, the URL at test case interface is called from template file, search test case position
The data resource put and included, then directly sends test request to server from test case interface.
Preferably, the system also includes:
Information extraction unit, URL, test data and expection for extracting the test case interface
Check value, and store.
The URL at test case interface, the test data that test case interface is included are extracted in advance, and test case is set
The expected check value of verification, above- mentioned information is stored in fixed template file, and template file is numbered so that its with
Test case is corresponded.Because each test case has unique corresponding template file, and template file is stored
URL, test data and expected check value that test case interface is included, therefore when testing test case, can root
The to be tested data that include are quickly found out in test case URL and test case according to template file, and the searching for simplifying URL is called
Process, has saved the testing time;Meanwhile, also can quickly find corresponding expected school when subsequently needing to call expected check value
Value is tested, testing efficiency is further improved.
Actual check value determining unit 23, for after server responds the test request, calling registered in advance connecing
The parsing of mouth function is not the response results of the server of empty test request, draws actual check value;
After test request is received, whether the data to be tested included in detection test request are sky to server,
Data to be tested are not space-time, respond the test request, return to JSON (JavaScript corresponding with testing data
Object Notation) formatted data.Interface function registered in advance receives the JSON formatted datas, and it is parsed.
The actual check value of test case is drawn according to analysis result.
Further, the system also includes:
Empty request for test unit, for being space-time in the test request, obtains the hypertext markup at test case interface
Language html, verifies checkpoint, and return to assay according to test case.Test request test request for sky refers to
In the testing data that includes be sky.
Test result determining unit 24, for comparing the actual check value and expected check value, obtains according to comparative result
Go out the test result of test case.
In the step, JSON formatted datas are parsed in interface function, after obtaining the actual check value of test case,
Call the expected check value corresponding with test case being stored in advance in template file, relatively more described actual check value with it is described
Expected check value;When the actual check value is identical with the expected check value, test case runs succeeded;If the two is not
Together, then test case performs failure.
Preferably, the system also includes:
Test result transmitting element, for the synchronous storage test result to fixation catalogue under, and send the test
Result is to specified address.
After all use-case end of runs, under operation result automatic synchronization to fixed catalogue, according to STMP (Simple
Mail Transfer Protocol) agreement sends test report to specified address, and so that user checks, the specified address can be with
To specify the address of mailbox, or specify receiving terminal.
In second embodiment of the invention, page start unit receives test case, the test case is judged, root
Whether user role information is included according to test case, calling interface opens test case interface in different ways.Test please
Ask transmitting element that the URL at test case interface is called from template file, test request is sent to server;The actual verification of test
Value determining unit after server responds the test request, the response results of calling interface function resolution server, while returning
Actual check value is returned, the actual check value of test result determining unit draws the test knot of test case with expected check value
Really.Test case URL, test data and expected check value are directly called in the present embodiment from template file, it is not necessary to user
The logical operation of complexity is carried out in client, while reducing tester and developer's workload, the standard of test is improve
True rate and testing efficiency.
Those of ordinary skill in the art are it is to be appreciated that the list of each example described with reference to the embodiments described herein
Unit and algorithm steps, can be realized with the combination of electronic hardware or computer software and electronic hardware.These functions are actually
Performed with hardware or software mode, depending on the application-specific and design constraint of technical scheme.Professional and technical personnel
Described function, but this realization can be realized it is not considered that exceeding using distinct methods to each specific application
The scope of the present invention.
It is apparent to those skilled in the art that, for convenience and simplicity of description, the system of foregoing description
With the specific work process of unit, the corresponding process in preceding method embodiment is may be referred to, will not be repeated here.
The above, specific embodiment only of the invention, but protection scope of the present invention is not limited thereto, and it is any
Those familiar with the art the invention discloses technical scope in, change or replacement can be readily occurred in, should all contain
Cover within protection scope of the present invention.Therefore, protection scope of the present invention described should be defined by scope of the claims.