商城网站页面模板,什么网站可以做英语题,石家庄企业网络推广,伏羲方舟网站建设参数化
通过参数的方式传递数据#xff0c;从而实现数据和脚本分离。并且可以实现用例的重复生成与执行。
参数化应用场景 测试登录场景 测试登录成功#xff0c;登录失败(账号错误#xff0c;密码错误)创建多种账号: 中⽂文账号#xff0c;英⽂文账号 普通测试用例方法 …参数化
通过参数的方式传递数据从而实现数据和脚本分离。并且可以实现用例的重复生成与执行。
参数化应用场景 测试登录场景 测试登录成功登录失败(账号错误密码错误)创建多种账号: 中⽂文账号英⽂文账号 普通测试用例方法 Copy 多份代码 or 读⼊入参数?一次性执⾏多个输⼊入参数
def test_param_login_ok():# 登录成功username rightpassword rightlogin(username,password)def test_param_login_fail():# 登录失败username wrongpassword wronglogin(username,password)参数化实现方案
pytest 参数化实现方法装饰器pytest.mark.parametrize
pytest.mark.parametrize(username,password,[[right,right], [wrong,wrong]])
def test_param(username,password):login(username,password)Mark参数化测试函数使用
单参数多参数用例重命名笛卡尔积
参数化单参数情况
单参数可以将数据放在列表中
search_list [appium,selenium,pytest]
# 参数化实现测试用例的动态生成每一条测试数据都会生成一条测试用例
pytest.mark.parametrize(name,search_list)
def test_search(name):assert name in search_list参数化多参数情况
将数据放在列表嵌套元组中将数据放在列表嵌套列表中
# 数据放在元组中
pytest.mark.parametrize(test_input,expected,[(35,8),(25,7),(75,12)
])
def test_mark_more(test_input,expected):assert eval(test_input) expected
# 数据放在列表中
pytest.mark.parametrize(test_input,expected,[[35,8],[25,7],[75,12]
])
def test_mark_more(test_input,expected):assert eval(test_input) expected参数化用例重命名-添加 ids 参数
通过ids参数将别名放在列表中
# ids 为用例起个别名ids 列表参数的个数要与参数值的个数一致
pytest.mark.parametrize(test_input,expected,[(35,8),(25,7),(75,12)
],ids[add_358,add_257,add_3512])
def test_mark_more(test_input,expected):assert eval(test_input) expected参数化用例重命名-添加 ids 参数中文
pytest 不支持中文格式 pytest.mark.parametrize(test_input,expected,[(35,8),(25,7),(75,12)
],ids[3和5相加,2和5相加,7和5相加])
def test_mark_more(test_input,expected):assert eval(test_input) expected# 创建conftest.py 文件 将下面内容添加进去运行脚本
def pytest_collection_modifyitems(items):测试用例收集完成时将收集到的用例名name和用例标识nodeid的中文信息显示在控制台上for i in items:i.namei.name.encode(utf-8).decode(unicode_escape)i._nodeidi.nodeid.encode(utf-8).decode(unicode_escape)参数化笛卡尔积 两组数据 a[1,2,3]b[a,b,c] 对应有几种组合形势 (1,a),(1,b),(1,c)(2,a),(2,b),(2,c)(3,a),(3,b),(3,c)
# 装饰器方法由近及远执行先取a再依次取b
pytest.mark.parametrize(b,[a,b,c])
pytest.mark.parametrize(a,[1,2,3])
def test_param1(a,b):print(f笛卡积形式的参数化中 a{a} , b{b})最后感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 这些资料对于【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴上万个测试工程师们走过最艰难的路程希望也能帮助到你