当前位置:网站首页>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 .
边栏推荐
- KDD 2022 | EEG AI helps diagnose epilepsy
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
- Ubantu check cudnn and CUDA versions
- Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
- Loop structure of program (for loop)
- Beginner redis
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
- Paging of a scratch (page turning processing)
- Leetcode 208. 实现 Trie (前缀树)
猜你喜欢
VMware Tools installation error: unable to automatically install vsock driver
测试/开发程序员的成长路线,全局思考问题的问题......
Recoverable fuse characteristic test
Mathematical modeling learning from scratch (2): Tools
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
Four commonly used techniques for anti aliasing
Building core knowledge points
False breakthroughs in the trend of London Silver
vSphere实现虚拟机迁移
2020.2.13
随机推荐
Dede collection plug-in free collection release push plug-in
Recursive method to realize the insertion operation in binary search tree
FFT 学习笔记(自认为详细)
C language programming (Chapter 6 functions)
毕设-基于SSM高校学生社团管理系统
95后CV工程师晒出工资单,狠补了这个,真香...
程序员搞开源,读什么书最合适?
I'm interested in watching Tiktok live beyond concert
Opinions on softmax function
Live video source code, realize local storage of search history
Overview of Zhuhai purification laboratory construction details
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
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
视频直播源码,实现本地存储搜索历史记录
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
Mysql--- query the top 5 students
Four commonly used techniques for anti aliasing
Pbootcms plug-in automatically collects fake original free plug-ins
The growth path of test / development programmers, the problem of thinking about the overall situation
Nmap: network detection tool and security / port scanner