当前位置:网站首页>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 .
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
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 ):
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 ?
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
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 .
边栏推荐
- 朝招金安全吗 会不会亏损本金
- Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
- WGet: command line download tool
- Threedposetracker project resolution
- Redis' cache penetration, cache breakdown, cache avalanche
- Recursive method converts ordered array into binary search tree
- About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
- 基於DVWA的文件上傳漏洞測試
- KDD 2022 | EEG AI helps diagnose epilepsy
- Unity | 实现面部驱动的两种方式
猜你喜欢
Idea sets the default line break for global newly created files
Some features of ECMAScript
Kotlin basics 1
KDD 2022 | EEG AI helps diagnose epilepsy
Cf:h. maximum and [bit operation practice + K operations + maximum and]
3D model format summary
Finding the nearest common ancestor of binary search tree by recursion
黄金价格走势k线图如何看?
Dede collection plug-in free collection release push plug-in
ubantu 查看cudnn和cuda的版本
随机推荐
Mysql--- query the top 5 students
Cve-2017-11882 reappearance
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
File upload vulnerability test based on DVWA
JVM_ 15_ Concepts related to garbage collection
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
Xunrui CMS plug-in automatically collects fake original free plug-ins
The population logic of the request to read product data on the sap Spartacus home page
Hundreds of lines of code to implement a JSON parser
伦敦银走势中的假突破
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
视频直播源码,实现本地存储搜索历史记录
MCU realizes OTA online upgrade process through UART
Leetcode study - day 35
3D model format summary
SPIR-V初窥