当前位置:网站首页>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 …….

原网站

版权声明
本文为[Little brother said test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050335534294.html