当前位置:网站首页>Basic process and testing idea of interface automation

Basic process and testing idea of interface automation

2022-07-06 01:17:00 Horse killing chicken test

General steps of interface automation :

1、 Send a request

2、 Analysis results

3、 The verification results

Define three business-related classes

1、 One for packaging HTTPclient, Used to send requests

2、 Analysis results xml Class

3、 A class used to compare test results with expectations , Used to verify

4、 Classes that automatically generate reports : Automatically send reports or something

(locust Of python Tools )

Service level :Web server( service ) Database( Persistence tools - database )、Cache( Short time persistence tool - cache )

The interface test :

1、 Structural data

(1) Construct through the interface

For example, get one blog Article information of , How to construct data ?( Where did the article come from ??)— return blog Information

By adding the interface of the article , Temporary construction data (blog article ), Then, when asserting, check whether it is self-made data —— Interface coupling ( When two program modules are related, it is called coupling .)— Interface coupling with article making ( If the interface for creating the article hangs , Back then blog The interface will hang up )

Bus card recharge depends on Alipay's payment interface service. , There will be a price for calling the payment interface , So simulate a payment interface , All through mockserver( Test pile ) To simulate the service of payment interface ---- Whatever the input is , Return always successful or fixed

(2) Through persistent layer construction ( Better )

It means inserting data directly into the database

2、 Call interface

postman/jmeter–win

CURL-linux

Paw–mac

3、 Assert the interface return

Through different inputs - Judge different expectations ---- Data driven ( input data )
Assertion reference method : Compare database values ,code verification

4、 Use case design for interface testing

Functional test cases
Business logic design
The test cases of business logic are mainly designed for the processing logic of the service interface , This kind of use case design is not aimed at whether a function point is realized , Instead, it verifies the processing logic of the interface and some interdependent services , It is usually carried out according to the logical flow chart of the interface . For example , Two actions in the shopping system : Log in and place an order , These two businesses are interdependent , The order placing operation must be completed after login ( In login mode ), Otherwise, the order cannot be completed , At this time, we can design such a case: Place an order without logging in , See how the server handles .

 Insert picture description here

You can see that there are two judgments in this piece , We need to design use cases for different judgment branches , To ensure that all branches involved in the flowchart are covered by test cases . The different branches involved in the diagram are :
1.abdf;
2.acg;
3.abdeg;
Corresponding , Our use case should be :
1.userInfo != null && value(userGroup) != 0;
2.userInfo == null;
3.userInfo != null && value(userGroup) == 0;
The use case design of business logic is mainly based on the logic flow chart inside the service interface , Use case design for the judgment and branches in the flow chart , Ensure that each logic of the server interface is covered by test cases .

Exception handling
The interface between the server and the client is usually through HTTP Request to pass data , When sending a request , The client will carry various parameters , At this time, the server will perform different processing according to different parameters , Therefore, exception handling is mainly for the parameters in the request : Such as parameter addition and default 、 The data type of the parameter is wrong , The parameter carries the wrong value 、 The parameter is null, etc , This requires us to construct different parameter exceptions according to various parameters in the interface document , Check the response of the server .

Performance and security
Server performance is often a very important concern , In the actual test, we mainly focus on the interface QPS The number , as well as CPU And memory usage , Usually with the help of other tools, such as LoadRunner Perform performance testing . In terms of security , Mainly consider some common security policies, such as request encryption 、sql Injection, etc .

Two 、 Interface test example

1、postman test
 Insert picture description here

2、python test

1 # coding:utf-8
 2 import requests,unittest
 3 class V2ETestCase(unittest.TestCase):
 4     def test_ger_node_api(self):
 5         python_node_id = 90
 6         url = "https://www.v2ex.com/api/nodes/show.json"
 7         node_name = 'python'
 8         querystring = {"name":node_name}
 9         res = requests.request("GET", url, params=querystring).json()
10         print res
11         self.assertEqual(res['id'],python_node_id)
12         self.assertEqual(res['name'], node_name)
13 
14 if __name__=='__main__':
15     unittest.main()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Run on the command line ( For automated testing in the future ):
 Insert picture description here
Reports can be generated HTML Formal - add

python For example :

unittest library

Requests library

Json

Dict Dictionaries

assert Assertion

use postman Do interface tests , choice get still post, Join data sending request , View the returned results — Then make assertions for the interface ( Point at the top right code, choice js Language , Write assertion )

When the data returned by the interface is dynamic , For example, the latest comments on a website article ---- Or the test environment , Build an exclusive testing environment , No new data is generated , The same interface can be tested — Equivalent to static dynamic data

“ How to do interface test ” This problem can be divided into two problems :
How to design interface test cases ?
How to perform interface testing ?
 Insert picture description here

How to perform interface testing ?
Fiddler、SOAPUI、PostMan Can do semi-automatic interface automation test ;
Use Robot Framework Do fully automated interface automation testing ;
Use your own code to do automatic interface testing , Such as Java+testNG;

Automated interface testing + Ideas for generating reports :
At the beginning of the test phase of the interface , I use POSTMAN To manually test the interface , After passing the single interface test , Put test cases Copy To Jmeter in , As the basis for subsequent regular implementation , After all interfaces are manually measured , use Jmeter+Ant+Jenkins To regularly check the daily interface , And generate test reports , Then write a daily monitoring test report of the crawler , If there is an exception , Send e-mail alarm .

1、 The daily history report must also be preserved
2、 Email notification in case of failure
 Insert picture description here
Jenkins There are email alarms and report Show plug-ins ~ The landlord doesn't have to write it himself ...

Finally, it should be the test report , Integrated into automated interface testing , The daily interface test report is also very important ,Jmeter Although the test report is also very clear , But it's not what I want , My ideal test report should have one or two points

Test pass rate
The process of each test shows
The test pass rate is convenient for those who view the report to intuitively understand the test results .

The display of the test process needs to show the following contents : test result 、 Request address 、 Input parameters 、 Output results 、 assertion results . And the identification of success and failure needs to be very obvious .

原网站

版权声明
本文为[Horse killing chicken test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140134469609.html