当前位置:网站首页>简介
简介
2022-07-28 09:58:00 【互联网金融打杂】
简介
对于经常借助于使用自动化手段测试的同学来说,无论使用接口自动化工具,还是自研的测试框架,一个完整的自动化用例,断言部分绝对是重中之重,因为断言的颗粒度在一定程度上能反映用例质量,必然断言颗粒度越细,越可能发现问题,对于接口测试来说,接口返回结果断言是必须的,但是这还不够,更建议对落库的数据与接口的request中重要字段进行断言, 而断言实质也是数据之间的比较,例如相等、包含、非空等。
今天介绍的Python库assertP就是这样一个方便测试同学高效断言的工具,测试同学直接将数据库取出的数据作为实际结果 与 预期结果进行比较。它支持相等断言、包含断言、非空断言、JSON断言,具体使用方法介绍如下。
pip install assertP实践
- 结合数据库做断言。首先,新建一个测试表al_pay,造几条数据。
-- Create Table CREATE TABLE `al_pay` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `user_id` varchar(11) COLLATE utf8mb4_bin DEFAULT NULL, `pay_status` varchar(11) COLLATE utf8mb4_bin DEFAULT NULL, `pay_amount` int(11) DEFAULT NULL, `pay_cur` varchar(11) COLLATE utf8mb4_bin DEFAULT NULL, `order_id` varchar(30) COLLATE utf8mb4_bin NOT NULL DEFAULT '', `ext` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;测试代码:
import pymysqlfrom assertP import AssertPy_multi, AssertPy# 连接数据库, 和mysql服务端设置格式一样(还可设置为gbk, gb2312)conn = pymysql.connect(host="localhost", user="root", passwd="123456", db='article', charset='utf8', port=3306)cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)# 执行sql语句select_sql = "select order_id, user_id, pay_status, pay_amount from al_pay where order_id=%s;"cursor.execute(select_sql, ("2022010818343700000002",))act = cursor.fetchall()[0]exp = {'order_id': '2022010818343700000001', 'user_id': '20210100002', 'pay_status': 'CLOSED'}# 断言AssertPy('al_pay', act, exp)conn.commit()cursor.close()conn.close()- 包含关系断言
act = {'pay_amount': "2000", 'pay_cur': 'RMB', 'order_id': '2022010818343700000001', 'ext': '{"user_name": "QA", "currency": "RMB"}'}exp = {'pay_amount': "CONTAINS_CHECK:2000", 'pay_cur': 'RMB', 'order_id': '2022010818343700000001', 'ext': '{"user_name": "QA", "currency": "RMB"}'}AssertPy(tName, act, exp)- JSON断言
act = {'ext': '{"user_name": "QA", "currency": "RMB"}'}exp = {'ext': 'JSON:{"user_name": "QA", "currency": "USD"}'}AssertPy(tName, act, exp)- 多条数据断言
tName = "TestTable" act = [{'order_id': '2022010818343700000003', 'user_id': '20210100002', 'pay_status': 'PAYING'}, {'order_id': '2022010818343700000003', 'user_id': '20210100001', 'pay_status': 'SUCCESS'}] exp = [{'order_id': '2022010818343700000003', 'user_id': '20210100002', 'pay_status': 'PAYING'}, {'order_id': '2022010818343700000003', 'user_id': '20210100001', 'pay_status': 'SUCCESS'}] AssertPy_multi(tName, act, exp)更多断言类型,扩展中。。。
附
assertP:https://pypi.org/project/assertP/
Selquel pro:www.sequelpro.com/
Python texttable:https://pypi.org/project/texttable/
PyMySQL:https://pypi.org/project/PyMySQL/
logging:https://docs.python.org/3/library/logging.html
边栏推荐
- SuperMap iServer发布管理以及调用地图服务
- Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
- Installing MySQL for Linux operating system (centos7)
- 不登高山,不知天之高也;不临深溪,不知地之厚也
- leetcode076——数组中的第 k 大的数字
- uni-app进阶之创建组件/原生渲染
- 广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!
- ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
- (十)defer关键字
- 为什么要考一级建造师,一建证书含金量有多高?
猜你喜欢

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?

ES (8.1) certification topic

MySQL架构原理

OSPF的拓展配置,选路原则,防环及重发布

广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!

剑指offer

图解 3 种主流企业架构模式(建议收藏!)

二分、三分、01分数规划【第III弹】

什么样的知识付费系统功能,更有利于平台与讲师发展?

In retaliation for the dismissal of the company, I changed all code comments of the project!
随机推荐
Elk real time log analysis platform
2022 uni app parsing token standard - use jsrsasign - climb the pit
Holy Grail of web and double wing layout, float, clear, both
Function introduction and description of @jsontype annotation in fastjson
10 minute quick start EVs [play Huawei cloud]
Description of landingsite electronic label quppa firmware entering DFU status
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
银行入职考试要点汇总
Voice chat app - how to standardize the development process?
In retaliation for the dismissal of the company, I changed all code comments of the project!
16、字符串反转
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
JS promotion: the underlying principle of flat tiling
Which strings will be resolved to null by fastjason?
Massive data topn problem
What are the advantages of MRO purchasing website for industrial products? One article will help you understand
Kubernetes
管道、管程、管态的区别