None of this, how dare you say you can test the interface?

1. Basic theory of interface testing

Interface test: Interface test is a test for testing the interface between system components. It is mainly used to test the interface between the system and other external systems, as well as the interface between various sub-modules inside the system. - Baidu Encyclopedia

Interface principle: Simulate the process that the client sends a request message to the server, the server makes judgments on the corresponding message after receiving the request message and returns the final result to the client, and the client receives the returned result again and responds.

Inspection focus: The focus of the test is to check the correctness of interface parameter transfer, interface function implementation, and output results, as well as the integrity and rationality of fault-tolerant handling of various abnormal situations.

Interface type: internal interface and external interface, the internal interface is the interface developed by the program, the call between methods or modules, and the external interface is the external access call interface, such as the WeChat login of King Glory and the payment function of Alipay, etc. external interface.

Interface classification: webservice interface and http api interface. The webService interface uses the soap protocol for transmission and is transmitted through http. It is one of the special versions of HTTP POST. It follows a special xml message format (both request and return are xml), and the http api interface Using the http protocol, the calling method is distinguished by the path, and the key-value request is used, and the returned message is usually json.

The essence of the interface: the essence of the interface is a public function class, which can be understood as a channel for sending and receiving data transmission. When sending a get or post request, it is actually sent from the channel. return data.

Test scope: interface function, interface performance, interface stability and interface security, etc.

If you want to learn interface automation testing, here I recommend a set of videos for you. This video can be said to be the number one interface automation testing tutorial on the entire network at station B. At the same time, the number of online users has reached 1,000, and there are notes to collect and use. Technical exchanges of various masters: 798478386    

[Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (the latest version of actual combat)_哔哩哔哩_bilibili [Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (actual combat) The latest version) has a total of 200 videos, including: 1. [Interface Automation] The current market situation of software testing and the ability standards of testers. , 2. [Interface Automation] Fully skilled in the Requests library and the underlying method call logic, 3. [Interface Automation] interface automation combat and the application of regular expressions and JsonPath extractors, etc. For more exciting videos, please pay attention to the UP account. https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337&vd_source=488d25e59e6c5b111f7a1a1a16ecbe9a

2. Why interface testing is needed

1. Stabilize the bottom layer of the code: In the early stage of development, the bottom layer content cannot be detected at the business level, and the bottom layer of the code is not stable and reliable. Therefore, it is necessary to perform interface testing on the bottom layer content, otherwise errors in the bottom layer code may cause more external systems or call modules mistake.

2. Low-cost and high-efficiency: When the initial development and the resource design are not completed, early intervention in the testing work will expose problems in advance, which conforms to the concept of quality advancement, and can significantly and effectively control the testing cost, and the interface can be automated and continuously integrated, so there will be more high long-term returns.

3. The scope of testing is wider: Most of the interface tests are to check and test the system interface in all aspects from the user's point of view. Whether it is a software project or a game project, the interface test will cover part of the business logic, so the interface test It can also assist business testing during testing.

4. Improve interface security: The test scope of interface security is mentioned above. In terms of interface security, the restrictions on the client side are easy to avoid bypassing. It is also necessary to test the restrictions on the server side. When some private data is involved, the interface needs to be verified. encrypted transmission, such as user passwords, ID cards, bank card information, etc.

5. Guarantee system stability: Interface testing can ensure data transmission and fault tolerance between systems, thereby improving system-level stability.

Summarize:

The advantages of interface testing: improve overall testing efficiency, reduce the cost of R&D testing, comprehensively improve product quality, and reduce follow-up maintenance resources.

3. How to carry out interface testing

3.1. Interface development method

Business level:

Common interface testing tools: Postman, Jmeter, SoupUI, etc.

The principle of the interface test tool: simulate the request and data reception through the interface test tool to realize data transmission.

Code level:

Interface automated testing: through code implementation, send a request to judge the correctness of the interface through code assertions.

ps: In the follow-up automation articles, teaching interface automation framework construction, continuous integration, etc. will be discussed.

3.2. Interface testing process

In real project work, the process of interface testing is roughly divided into the following steps (different companies have some differences in the process):

1. When the company has an interface testing requirement or the testers receive the interface testing task, they begin to formally intervene in the process stage of the interface testing.

2. The developer provides the interface document. After getting the interface document, the tester is familiar with the requirement document first, and understands the functions and related information of each interface. (Including but not limited to server address and port, request method, request parameters, constraints, return status code, etc.)

3. After the testers are familiar with the requirements document, they start to intervene in the writing of test cases. Same as business testing, normal and abnormal request parameters and the correctness of corresponding response message data need to be considered.

4. Finally, the use case can be executed through the interface testing tool, such as Postman, Jmeter, etc. can be used. For example: Jmeter can first establish a thread group, add http requests, write related request addresses, ports, and request parameters, and set up parameterization. Add an assertion, and finally add a result tree before running. The principle of Postman and Jmeter is the same, but the operation method is different. I won’t elaborate here. Friends who are interested can find related tool instructions and information online.

5. After the operation is completed, check whether the interface is passed. If the interface test fails, the first step is to check whether there is any error in the request method, parameters and other information. If there is no error, check the network environment. If there is no problem, It may be that there is a problem with the interface itself. First use your own cognition to judge whether it is a front-end or back-end problem. After the judgment is completed, the bill of lading will be sent to the development and relevant log information will be attached until all confirmations are completed. It is worth mentioning that in the process of business interface testing, more attention will be paid to failed interfaces, and in the process of interface automation, it is also necessary to pay attention to the interfaces that pass the test for quality improvement and report output.

picture

3.3. Interface testing requirements

An interface requirements document, the core elements mainly include the following:

Document cover: The cover is the interface requirement document of xx company, with the company name and company logo and marked as a confidential document, the version number of the requirement document, the date of document creation, etc.

Revision record: usually in the form of a table, which at least includes the revised version and date, revision description, revision person, review time and reviewer, etc.

Interface description: interface access address format, interface address example, return result description, etc. (status code and related comments)

Interface information: module name, submodule, business description, interface name, request method, request format, response format, request parameters, result description, return example, etc.

Briefly introduce the content produced by the corresponding information in the interface information:

Module name: login, payment, etc.

Submodule name: WeChat login, QQ login, mobile phone number login

Business description: concisely summarize the functions of the interface

Interface name:

/login/wechat,/payment/personal

Request method: GET / POST etc.

Request format: application/x-www-form-urlencoded

Response format: application/json

Request parameters: mobile phone number, login password (including variable name, type, description and comment, whether it is required)

Result description: parameter content, variable name, type (such as string), return status code, etc.

Return example: An example of successful return, as shown in the picture in the 4.4 interface demonstration below

 

You can follow the company's interface documents.

3.4. Interface demonstration (Glory of the King, enterprise WeChat interface demonstration)

The author here demonstrates some interfaces to help you understand the interface, familiarize yourself with the interface requirements and instructions~

The glory of the king interface is shown as follows:

List of heroes:

interface address:

https://pvp.qq.com/web201605/js/herolist.json

Request method: GET

Input parameters: none

Output parameters:

picture

 Return results (partial display):

 

The enterprise WeChat interface is displayed as follows:

File upload interface:

The material is uploaded to get the media_id, which is only valid for three days

media_id can only be used by robots corresponding to uploaded files

Request method: POST (HTTPS)

interface address:

https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=KEY&type=TYPE

Using multipart/form-data

POST to upload files, the file identification name is " media "

Parameter Description:

picture

In the POST request packet, the media file identifier in form-data should contain information such as filename, filelength, content-type, etc.

filename identifies the name of the file display. For example, when using this media_id to send a message, the displayed file name is controlled by this field

Example request:

POST 

https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa&type=file HTTP/1.1

Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468

Content-Length: 220

---------------------------acebdf13572468

Content-Disposition: form-data; name=“media”;filename=“wework.txt”; filelength=6

Content-Type: application/octet-stream

mytext

---------------------------acebdf13572468–

Return data (no parameters passed):

{

“errcode”: 44001,

“errmsg”: “empty media data, hint: [1638347756075722279950035], from ip: 183.14.133.153, more info at https://open.work.weixin.qq.com/devtool/query?e=44001”

}

3.5. Interface test case design

Use case design format:

picture

Use case serial number: project name_module name_serial number

Interface module: corresponding interface modules, such as hero list, summoner skills, WeChat login module, voice module, etc.

Request method: usually the request method is GET, POST

Interface address: Usually there is a fixed address format to facilitate automated testing of the interface (the full address in the figure)

Interface parameter input: Some interfaces do not require interface parameter input, and some interfaces have interface input. If so, just fill it in

Key points and concerns of use case design:

(1) Whether the request data sent to the server is correct;

(2) Whether the data returned by the server to the client is consistent with the requirements and meets expectations;

(3) Check whether the interface in the database implements the corresponding function;

(4) Whether the response time of the interface meets the requirements of the requirements document

The scope of interface use case design considerations:

1. Business function: whether the function is realized

2. Business rules: Whether the defined description meets expectations

3. Request parameters: parameter length, size, format, etc.

4. Abnormal scenarios: parameter passing exception, operation exception, service exception, etc.

5. Data transmission: the correctness of data transmission results

6. Interface performance: correct interface performance, such as concurrency, etc.

7. Interface security: such as payment, recharge interface data tampering, etc.

ps: In the above range, the use case coverage and code coverage of the interface also need to be considered, at least in line with expectations

3.6, back-end interface test content

The so-called interface test, what content is tested on the back-end interface? The following picture will give you some help (the picture comes from the Internet):

Alright~ The above is all the content of this article, have you learned it? If you have any questions, remember to leave a message to discuss~ 

Guess you like

Origin blog.csdn.net/m0_73409141/article/details/131773904