菁英科技(卓目鸟学苑)- 专注软件测试菁英教育
标题:
接口测试-樊江飞-2021.03.19
[打印本页]
作者:
皮皮虾
时间:
2021-3-19 17:42
标题:
接口测试-樊江飞-2021.03.19
'''
pytest mark
标记
1
、跳过用例(有缺陷的用例跳过不执行)
2
、选择部分用例执行
,
工程中用例规模越来越大,包含界面自动化、接口自动化、性能、冒烟测试
只想执行冒烟测试的用例,怎么办。
自定义标记。
mark.
后面的字符串自己定义的。
自定义标记在
pytest.ini
中注册下,执行时,加参数:
-M=“smoke"
执行带
smoke
标记的用例
-m=“func or smoke”
执行带
smoke
标记或者带
func
标记的用例
-m=“func and smoke”
执行带
smoke
标记且带
func
标记的用例
-m=“func and not smoke”
执行带
func
标记,但是不带
smoke
标记的用例
'''
import
pytest
version =
'V1R1'
@pytest.mark.smoke
#
冒烟用例
def
test_001():
print
(
"
用例
1"
)
@pytest.mark.skip
(
"
因为
xxxx
缺陷,该用例执行失败,待缺陷解决后再执行
"
)
def
test_002():
print
(
"
用例
2"
)
#
前面的表达式为
true
时跳过,为
false
时不跳过
@pytest.mark.skipif
(version==
'V1R1'
,
reason
=
"V1R2
以上的版本增加的功能,
V1R1
尚不支持
"
)
def
test_003():
print
(
"
用例
3"
)
@pytest.mark.func
#
功能用例
def
test_004():
print
(
"
用例
4"
)
@pytest.mark.func
#
给类加上标记,类中每个用例都带有这个标记
class
Test001:
def
test_005(
self
):
print
(
"
用例
5"
)
@pytest.mark.smoke
#
冒烟用例
def
test_006(
self
):
print
(
"
用例
6"
)
def
test_007(
self
):
print
(
"
用例
7"
)
def
test_008(
self
):
print
(
"
用例
8"
)
'''
用例有多个参数时,参数之间是全排列的。
一个字符串搜索的功能,有
3
个输入:
要搜索的字符串(大写、小写、混合)、
搜索方向(向上搜索、向下搜索)
是否区分大小写(区分、不区分)
'''
import
pytest
@pytest.fixture
(
params
=[
"Hello"
,
"HELLO"
,
"Hello"
])
def
searchStr(request):
return
request.param
@pytest.fixture
(
params
=[
"
向上搜索
"
,
"
向下搜索
"
])
def
fangXiang(request):
return
request.param
@pytest.fixture
(
params
=[
"
区分
"
,
"
不区分
"
])
def
daXiaoXin(request):
return
request.param
#
共执行
3*2*2=12
个用例
def
test_search(searchStr,fangXiang,daoXiaoXin):
#
字符串前面加
f,{}
中的内容打印时,用变量的值替换
print
(
f"
测试搜索功能,要搜索的字符串为:
{
searchStr
}
,
搜索方向为:
{
fangXiang
}
,
是否区分大小写:
{
daoXiaoXin
}
"
)
'''
第三个版本:使用数据驱动的方式,实现注册接口的测试
'''
import
pytest
import
requests
@pytest.fixture
(
params
=[(
"123"
,
"123456"
,
'
手机号格式不正确
'
),(
"13227907985"
,
"12345"
,
'
密码长度必须为
6~18'
)])
def
data(request):
return
request.param
def
test_register(data):
print
(
"
测试数据为:
"
,data)
url =
"http://192.168.2.36:8089/futureloan/mvc/api/member/register"
cs = {
"mobilephone"
: data[
0
],
"pwd"
: data[
1
]
}
r = requests.get(url,
params
=cs)
print
(r.text)
assert
r.json()[
'msg'
] == data[
2
]
##########################################################################################
欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/)
Powered by Discuz! X3.4