first, what is API interface testing?
There are several API interfaces that individuals divide into three categories.
The first is the function level, which tests the parameters of the interface, such as:
int GetResult (string key, string ID, int ticket).
The second is object-level, development in the use of API interface, the introduction of the package name, before using to declare an object, then you can use the method provided by the object, while testing, you need to test the functionality of the API and data input correctness. The second and the first difference is that we only need to focus on the interface provided to the user can be, do not care about the interface calls other functions, compared to the first, the granularity of the test is larger, the scope is smaller.
The third is the interface of the HTTP protocol, the app client and the back-end service connection, generally using the HTTP protocol, the client through the get and post methods to obtain data from the backend services. The third is more granular than the second, and we are concerned with fewer interfaces, but these interfaces are core functions.
second, why to test API interface?
The app backend service, when there is a feature abnormality, or spit out abnormal data, can cause the client function is abnormal, even crash phenomenon. The client crashes due to data problems, and if fault tolerance is not in place, the app can never start. This kind of harm to the user, to the company, is huge. It is therefore necessary to test the API interface.
third, how to test API interface?
There are many methods for testing API interfaces, such as: Use Fiddler to send Get, post function to verify. The downside is that after testing it again, it takes time to do it manually again during regression testing.
It is indeed a good idea to use Python's request for API interface testing, which is coded for API interface testing. But the problem is, time. There may not be time to do this script during the limited test time. If you complete this script, you need at least one round of manual testing to see what the expected return value will be.
Is there a tool that, after manual testing, does not need to write too much code and can immediately automate regression with the cases of functional testing?
Answer: Yes. Postman is the tool that can be used like a fiddler or a script.
Construction of the environment
Install Chrome Browser
Open in the Chrome Address bar:Https://chrome.google.com/webstore/search/postman
Add Postman and Postmaninterceptor
Note:
Postman is an independent chromeapp;
Postman Interceptor can synchronize data with postman and send browsing history from Chrome to Postman.
In the Chrome Address bar Open: chrome://extensions/, click "Details" under Postman, fill in the shortcut to the desktop.
Start Postman and register an account.
Use of Postman
Open the Postman Interceptor Sync switch in the Chrome browser
Start post man, turn on the sync switch
Visit Sogou homepage in Chrome browser and see the record of Access under Postman history tab
Fill in a checkpoint.
① Select the request to check, such as: m.sogou.com, click the Send button to the right of the GET request, and in the body section you can see the returned data.
② Click on the tests at the bottom of the request section, and from the right checkpoint, select the point you want to verify, such as: Verify that the returned content contains "", click "Response body:contains string", and then add a row of check statements in the quarantine area, and change the string to be checked to " ”。 Then click Save to add the checked request to collections.
5. Collection of automatic run checks
① Click on "Collections" tab, select the Set up, click on the "Run" button of the collection to enter the test page. Select on the test page, Start test
6. The test results will be displayed in the Results tab on the right.
7. Postman supports a variety of different requests. From the Get list, you can select the type you want to test.
use of Newman
In the correctness test, you can save all the test requests, which can be used in subsequent bug verification and regression. In the future, when the same module is being tested, the script that runs before it can complete the regression verification of previous functions.
Newman is a command-line tool that requires a npm,node environment to be installed on the PC. After the installation is complete, install Newman with the following command.
Once the installation is complete, you first need to save the script in postman to local and then execute it on the command line to generate the test report.
① Save the Postman collections to Local.
② executing postman scripts at the command line
③newman-c test.json.postman_collection–hresult.html
When the ④ runs, an HTML results page is generated.
The advantages of postman are:
1. Anyone can use, do not need coding ability;
2. The cases of function test can be changed into automation use case instantly;
3. Look at the return of the data, as with fiddler.
HTTP API Interface Test Tool Postman Introduction