当前位置:网站首页>Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
2022-07-05 03:49:00 【Little brother said test】
Preface
Looking for a job recently , Because it is a pure server-side test , So during the interview, the interviewer will inevitably ask , How to design interface test cases , How to do interface automation test ? I will take a symbolic test of basic skills .
Next is interface testing , Or service side testing , Sort out my thoughts ~
One 、 What is an interface
Q: What is an interface ?
A: Let's give you an example , Thirsty and want to drink water , There happens to be a water dispenser next to it , The faucet is an interface
Then the same is true in the procedure , You buy clothes on the app 、 Ordering meals 、 rent an apartment 、 Book air tickets, food, shelter and transportation , In fact, they are accessing the interface of the corresponding program .
Take the example I want to give below to illustrate :
There is a login page , You have to go to the website , You need to enter your account password , Use the account and password as the request parameter to enter the login interface , At this time, the client will send a login request to the server , After the server authentication and verification pass , Then he climbed up .
This completes an interface request , Or run an interface test case .
Two 、 What are the common types of interface requests ?
Common interface request types are :post get put delete
I usually ask get and post The difference between , Don't understand Baidu
that , Design interface test cases , First, you need the interface contract , That is, interface documents .
What does the interface document look like , Look below ~
3、 ... and 、 Example of interface document
The test function is login page :https://xxx/account/signin(url I typed the code )
Address of the interface :https://xxx/account/signin( Think about the interface and code it , After all, there is a charge )
Request mode :POST
Interface description : Login interface of a website
【 Interface input parameters 】

【 Interface to return 】

【 Interface request example 】
{
"account": "[email protected]",
"password": "191004"
}
【 Interface returns an example 】
{
"code": 0,
"msg": "",
"data": {
"name": null,
"avatar": null,
"id": "7",
"account": "[email protected]",
"role": 3
}
}
Understand the interface contract , How to design interface test cases , Please read on .
Four 、 How to design interface test cases
First you have to have a framework
The interface has been tested for several years , Sort out a use case template , For a simple reference , Incomplete welcome to add ~

So based on this set of templates , We can design the use case of login interface in the interface contract
5、 ... and 、 Design test cases based on login interface
1. Parameter checking
account
- Required : No , An empty string , Pass on null, Do not transfer this field
- String type : Pass on int Type or other type
- Length check : Suppose the scope [1-20], Less than 1、 Greater than 20, stay 1-20 Within the scope of , The pass is too long
- enumeration : nothing
password
- Required : No , An empty string , Pass on null, Do not transfer this field
- String type : Pass on int Type or other type
- Length check : Suppose the scope [1-20], Less than 1、 Greater than 20, stay 1-20 Within the scope of , The pass is too long
- enumeration : nothing
2. Parameter combination
- Correct account password , Login successful , Return the data to get the user role and user information
- Wrong account , Password pairs , Login failed ,code1
- The account number is right , Wrong password , Login failed ,code1
- Wrong account , Wrong password , Login failed ,code1
3. Business logic
- The data flow : The login account is a database member , After logging on, the interface returns data Data found for the database
- jurisdiction : Administrator account 、 Ordinary user accounts 、 Operation account number
- Account type :qq mailbox 、 Corporate mailbox or other types of mailbox , Normal login , Phone number does not support
- Whether there is logic processing for multi terminal login , Do you want to limit the maximum number of users logging in
4. Security
- The password is visible in clear text
- You can't catch it
- Login authentication , Both the front end and the service end should be done
- token timeliness
- sql Inject
5. performance
- response time 200ms
- Concurrency number ( I feel no need to consider high concurrency when logging in , Specific business scenario analysis )
6. journal
- When measuring the interface , Follow the log
7. monitor
- The interface function is online , Pay attention to business requests and various exception monitoring
6、 ... and 、 What tools are commonly used for interface testing
- postman
- jmeter
- linux command curl Send an interface request
- python、java Write the script
All of the above , The fourth one is used for interface automation testing
7、 ... and 、 Interface automation test ideas
First step : Handmade case By writing code , Turn to automated testing case, Set up case Assertion of , Then run this batch case Let him execute automatically , First, let the code run roughly
The second step : Reduce repetitive code , Integrate the test data into parametric reading , Data driven
The third step : Optimize code readability , Pull out the general module
8、 ... and 、 Interface automation test practice
Complete the first step , It's simple , Write one , Other copy and paste , Change assertion , Change parameters

So what's the problem ?
- Add a new use case , I want to change one in the code , Parameters are also placed in the code , Looks tired , It's also very tiring to change .
Complete the second step , Put use cases in excel in , adopt pytest The built-in decorator is parameterized


Here we solve the problem of changing parameters in the first step , But there are still problems
- Code duplication is large , Add another use case later , That repeated piece needs to be written again
- obtain excel The method of data is put in the test case , Poor code readability , Our test cases had better not contain preconditions .
Complete step three , Extract read excel Data section , In a separate file , Bring up the part of parameter conversion and request initiation .
At the same time, it optimizes the acquisition excel Data section , The last step is to read the area , This has poor scalability , If I want to be in excel Riga use case , You need to change this area , So let him read this column directly , This will not affect the later casually .


It's much more refreshing , Add use cases , Just change excel, And then in testcase Add use cases , And the use case basically implements assertions .
If you want to add some logs , Or you need to check the database to make assertions, and so on , It can be optimized .
It's not easy to code words , Reprint please indicate the source , thank you ~
Learning resource sharing
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For thinking 【 Advanced test development 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….

边栏推荐
- UI自动化测试从此告别手动下载浏览器驱动
- [数组]566. 重塑矩阵-简单
- SPI and IIC communication protocol
- New interesting test applet source code_ Test available
- 問下,這個ADB mysql支持sqlserver嗎?
- How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
- [vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils
- 深度学习——LSTM基础
- An elegant program for Euclid‘s algorithm
- Difference between MotionEvent. getRawX and MotionEvent. getX
猜你喜欢

Learning notes of raspberry pie 4B - IO communication (I2C)

Some enterprise interview questions of unity interview
![Yuancosmic ecological panorama [2022 latest]](/img/55/0901109e4c865b77137610b4fe0624.jpg)
Yuancosmic ecological panorama [2022 latest]
![[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)](/img/99/bb05b6c48a9e70ca7ff77733d954b9.jpg)
[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)

About MySQL database connection exceptions
![[untitled]](/img/e0/52467a7d7604c1ab77038c25608811.png)
[untitled]

Thread Basics

线上故障突突突?如何紧急诊断、排查与恢复

Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time

A brief introduction to the behavior tree of unity AI
随机推荐
How to define a unified response object gracefully
speed or tempo in classical music
[Chongqing Guangdong education] 2777t green space planning reference questions of National Open University in autumn 2018
Use of kubesphere configuration set (configmap)
An elegant program for Euclid‘s algorithm
De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
Unity implements the code of the attacked white flash (including shader)
FBO and RBO disappeared in webgpu
postman和postman interceptor的安装
Learning notes of raspberry pie 4B - IO communication (I2C)
【web審計-源碼泄露】獲取源碼方法,利用工具
[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
NEW:Devart dotConnect ADO.NET
[web Audit - source code disclosure] obtain source code methods and use tools
Necessary fonts for designers
Ubantu disk expansion (VMware)
Class inheritance in C #
speed or tempo in classical music
Redis source code analysis: redis cluster
Google Chrome CSS will not update unless the cache is cleared - Google Chrome CSS doesn't update unless clear cache