1. What is an interface
Interface testing is a type of testing that tests the interfaces between system components. Interface testing is mainly used to detect the interaction points between external systems and internal subsystems. The focus of the test is to check the exchange of data, the process of delivery and control management, and the mutual logical dependencies between the systems.
Second, the role of the interface
As an Internet company, many resources and information need to be shared internally or circulated externally, and related data needs to be transmitted through interfaces.
Three, interface understanding
API interface is the abbreviation of Application Programming Interface, which is some predefined functions, including interface address, incoming parameters and return parameters.
From a non-R&D point of view, it can be simply understood that when certain data needs to be accessed, qualified parameters are passed in under normal conditions, and return parameters within the data range will be received.
From a research and development perspective:
Interface (hardware interface) refers to the communication rules between different functional layers of the same computer called interface.
An interface (software class interface) is a reference type that defines a contract. Other types implement interfaces to guarantee that they support certain operations. An interface specifies the members that must be provided by the class or other interfaces that implement it. Like classes, interfaces can contain methods, properties, indexers, and events as members.
Fourth, the interface tool
1. Postman ---> Application of Postman
It is an interface testing software developed by Google. It is easy to use and powerful. It can send any type of HTTP request (GET, HEAD, POST, PUT..), and can perform file upload, response verification, variable management, and environmental parameter management. , can also manage and run use cases in batches, and support use case export and import, and can perform automated testing of interfaces.
The disadvantage is that automated assertions are not powerful enough to perform continuous integration testing with jenkins and code management libraries.
2, jmeter
It is a free open source tool written in 100% pure Java. It is mainly used for performance testing, but it can also be used for interface testing. With post-processors and assertions, it can meet most interface testing scenarios. JMeter provides BeanShell programming capabilities , you can write more flexible test scripts, and you can realize interface and performance automation testing through jmeter+ant+jenkins.
3、soapUI
It is an open source testing tool, which can be checked and invoked through soap/http to realize the interface and performance test of Web Service. The tool can be used as a separate test software, and can also be integrated into Eclipse, maven2.X, Netbeans and intellij using plug-ins.
Five, the appearance of the interface
1. You can refer to the WeChat mini-program development API https://developers.weixin.qq.com/miniprogram/dev/api/
2. The figure below explains the torsion of the interface
Six, interface document
Interface Description:
Interface function: This interface is used to obtain the user's token information---login.
Interface request address:
https://xingzoushamodewoniu.com/long/api/login |
Request headers:
request header | request method | illustrate |
Content-Type | application/json | request method |
Request method: POST
Parameter type: JSON
Request example: most of them are json, the format is customized
{
"account": "小白龙",
"password": "123456",
"clientId": "long",
"responseType": "code"
}
Description of request parameters
field name | field description | Field Type | Is it required? |
account | username | varchar(30) | yes |
password | password | int(15) | yes |
clientId | Customer Number | varchar(50) | yes |
responseType | response type | varchar(50) | yes |
example response
Successful response encoding:
{
"code": "200",
"message": "OK",
"data": {
"code": "4dd529b3-c4b0-4066-a363-742c5b6b6e74_generate_token",
"accessToken": "eyJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiJVNjA3NkIwMTI0Q0VERkQwMDAxMTdFREU3IiwiZXhwIjoxNjM5NDY1NzYzLCJpYXQiOjE2MzkyMDY1NjN9.ZHkW6j6rfbyyRQ5ZSRW_Z1nRTiYqyiWgSINBEZA99UMw92H1eiy4JxxC6n3AIAcE3Y9j_p8ZNTtJWIsSlsFbOZfmAuOr2ih4oR0tpjCWLU1UTesVmn7tCkeTpbmjeNJolcd4X7knKIKuXyi88SC6ZIhMJRE1ZTI3eK4hJUCi6Rx50lcHvjV_HX2ZHqEly5wqvr_jQ0ZWXquNlGTrPRXofQ6cLawVea8Z_EnXermECQrjWpRelhKYyl2hlqGd48n46avHFAaxp3UZhy1TeE_xeLxYMaBOpUADcPaezSj2Q_Qbq4T24w83iV2JwGAKAVPMQgBjn68IYuucS-j7fxXqFQ",
"accountId": "U6076B0124CEDFD000117EDE7"
},
"extra": null
}
Response parameter description
Interface return code | Interface returns description |
200 | success |
201 | Request parameter error |
202 | wrong password |
7. Packet capture tool capture interface
Grab the following with the help of tools (Fiddler, Charles, Proxyman, Wireshark, Tcpdump, console{F12})
General
Request URL: https://xingzoushamodewoniu.com/long/api/login
Request Method: POST
Status Code: 200 OK
Remote Address: 127.0.0.1:7367
Referrer Policy: strict-origin-when-cross-origin
Response Headers
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Sat, 11 Dec 2021 07:14:39 GMT
Server: openresty
Set-Cookie: ac=ed09abaa400c19fff38a588d6c412c21; expires=Sun, 11-Dec-2022 07:14:39 GMT; Max-Age=31536000; path=/
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: PHP/7.1.12
X-RateLimit-Limit-second: 80000
X-RateLimit-Remaining-second: 79004
Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Content-Length: 134
Content-Type: application/x-www-form-urlencoded
Host: qac-qupost.qutoutiao.net
Origin: https://mp.qutoutiao.net
Refer: https://mp.qutoutiao.net/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36
Form Data
{
"account": "Little White Dragon",
"password": "123456",
"clientId": "long",
"responseType": "code"
}
Response
{
"code": "200",
"message": "OK",
"data": {
"code": "4dd529b3-c4b0-4066-a363-742c5b6b6e74_generate_token",
"accessToken": "eyJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiJVNjA3NkIwMTI0Q0VERkQwMDAxMTdFREU3IiwiZXhwIjoxNjM5NDY1NzYzLCJpYXQiOjE2MzkyMDY1NjN9.ZHkW6j6rfbyyRQ5ZSRW_Z1nRTiYqyiWgSINBEZA99UMw92H1eiy4JxxC6n3AIAcE3Y9j_p8ZNTtJWIsSlsFbOZfmAuOr2ih4oR0tpjCWLU1UTesVmn7tCkeTpbmjeNJolcd4X7knKIKuXyi88SC6ZIhMJRE1ZTI3eK4hJUCi6Rx50lcHvjV_HX2ZHqEly5wqvr_jQ0ZWXquNlGTrPRXofQ6cLawVea8Z_EnXermECQrjWpRelhKYyl2hlqGd48n46avHFAaxp3UZhy1TeE_xeLxYMaBOpUADcPaezSj2Q_Qbq4T24w83iV2JwGAKAVPMQgBjn68IYuucS-j7fxXqFQ",
"accountId": "U6076B0124CEDFD000117EDE7"
},
"extra": null
}
The above is the data obtained through the packet capture tool or the console of the browser (check, F12). This interface has gone through the process in the above figure, and finally the login is successful.
Eight, interface use case design
The principle of the interface test is to simulate the process that the client sends a request message to the server, the server processes the corresponding message after receiving the request message and returns a response to the client, and the client receives the response.
The method used in interface testing is actually consistent with black-box testing, and interface testing can even be understood as functional testing without an interface. It’s just that there are more test points for interface testing. In addition to various functional points that need to be verified on the interface, it also includes interface security and interface performance.
The design of general test cases should range from the verification of single interface parameters to the verification of the entire business function point, and some security and abnormal situations can also be verified.
The basic principles of interface use case design points are as follows: