httprunner学习(2)参数化数据驱动

参数化三种方式

  • 引用 CSV 文件
  • 直接指定参数列表
  • 调用 debugtalk.py 中自定义的函数生成参数列表

1.1 新建csv

httprunner学习(2)参数化数据驱动

1.2 关联参数

httprunner学习(2)参数化数据驱动

1.3 引用 CSV 文件

然后在 测试用例集中,就可以通过内置的 parameterize(可简写为 P)函数引用 CSV 文件。

httprunner学习(2)参数化数据驱动

1.4 执行测试

hrun ./testsuites/department.yml

httprunner学习(2)参数化数据驱动

2.直接指定参数列表

httprunner学习(2)参数化数据驱动

httprunner学习(2)参数化数据驱动

3.自定义的函数生成参数列表

在 debugtalk.py 中定义函数 get_id,生成指定数量的参数列表。

httprunner学习(2)参数化数据驱动
在测试集的 parameters 中就调用自定义函数生成指定数量的参数列表。
httprunner学习(2)参数化数据驱动

httprunner学习(2)参数化数据驱动