标签:ima tps size vertica pos pre sel post ase
上一篇里写的httprunner 3.x--variables变量和声明(变量和值一一对应) 中的variables是对 “一对一”的参数有用,
但对于变量需要多个数值,比如登录账号需要多个账号密码的,总不能一个账号密码写一个测试用例,这时候就需要用到关键字parameters
直接指定参数列表:该种方式最为简单易用,适合参数列表比较小的情况
【yml格式的测试用例】
config: name: "hz测试" parameters: uid: [1**97,1245] choujiang_id: [***,33] username: [**,mm] base_url: "https://lottery.hz.z****in.com" verify: False teststeps: - name: "接口test /lotteryTest.php" request: method: GET url: /lotteryTest.php params: uid: $uid choujiang_id: $choujiang_id username: $username validate: - eq : ["status_code", 200] - eq : ["body.status", 1]
其中打**的参数是正确,username是任意都行,所以上面的参数有8种组合
[1**97,***,**] [1**97,***,mm] [1**97,33,**] [1**97,33,mm]
[1245,***,**] [1234,***,mm] [1245,33,**] [1245,33,mm]
运行结果如下:
【pytest格式测试用例】
# NOTE: Generated By HttpRunner v3.1.3 # FROM: testcases/hetest_re.yml import pytest from httprunner import Parameters from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase class TestCaseHetestRe(HttpRunner): @pytest.mark.parametrize( "param", Parameters( {"uid": [1**7, 1245], "choujiang_id": [***, 33], "username": ["**", "mm"]} ), ) def test_start(self, param): super().test_start(param) config = ( Config("hz测试").base_url("https://lottery.hz.z*****in.com").verify(False) ) teststeps = [ Step( RunRequest("接口test /lotteryTest.php") .get("/lotteryTest.php") .with_params( **{ "uid": "$uid", "choujiang_id": "$choujiang_id", "username": "$username", } ) .validate() .assert_equal("status_code", 200) .assert_equal("body.status", 1) ), ] if __name__ == "__main__": TestCaseHetestRe().test_start()
然后用pytest方法运行
运行结果如下:
httprunner 3.x--参数化parameters(参数和值一对多,多对多等)
标签:ima tps size vertica pos pre sel post ase
原文地址:https://www.cnblogs.com/may18/p/13377901.html