当前位置:网站首页>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 .
边栏推荐
- Idea sets the default line break for global newly created files
- Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
- Overview of Zhuhai purification laboratory construction details
- DOM introduction
- Xunrui CMS plug-in automatically collects fake original free plug-ins
- 基於DVWA的文件上傳漏洞測試
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
- Vulhub vulnerability recurrence 74_ Wordpress
- golang mqtt/stomp/nats/amqp
猜你喜欢
Leetcode study - day 35
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
KDD 2022 | EEG AI helps diagnose epilepsy
Five challenges of ads-npu chip architecture design
vSphere实现虚拟机迁移
测试/开发程序员的成长路线,全局思考问题的问题......
黄金价格走势k线图如何看?
037 PHP login, registration, message, personal Center Design
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
随机推荐
logstash清除sincedb_path上传记录,重传日志数据
测试/开发程序员的成长路线,全局思考问题的问题......
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
Zhuhai's waste gas treatment scheme was exposed
Daily practice - February 13, 2022
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
3D model format summary
Recursive method to realize the insertion operation in binary search tree
Vulhub vulnerability recurrence 74_ Wordpress
[Arduino syntax - structure]
Spir - V premier aperçu
After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
WGet: command line download tool
KDD 2022 | EEG AI helps diagnose epilepsy
Beginner redis
ThreeDPoseTracker项目解析
基於DVWA的文件上傳漏洞測試
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
朝招金安全吗 会不会亏损本金