一、测试方案概述
- 基于工具类:
- Postman + Newman + Jenkins
- JMeter + Ant + Jenkins
- Apifox + Apifox-CLI + Jenkins
- 基于框架和平台:
- Python + Requests + Pytest + Allure + YAML + Logging + Jenkins
- 开发自动化测试平台
二、常见请求方法
1. GET 请求
import jsonpath
import requests
class TestApi:
# 获取 access_token 鉴权码接口
def test_get_token(self):
url = "https://api.weixin.qq.com/cgi-bin/token"
datas = {
"grant_type": "client_credential",
"appid": "YOUR_APPID",
"secret": "YOUR_SECRET"
}
res = requests.get(url=url, params=datas)
token = res.json()['access_token']
print(token)
**kwargs 是关键字参数的缩写,作用是接收函数调用时传入的多余关键字参数,并把它们打包成一个字典。
2. POST 请求
def post(url, data=None, json=None, **kwargs):
# url: 接口地址
# data: 参数 (表单/表格---x-www-form-urlencoded)
# json: 参数 (JSON---application/json)
# **kwargs: 可变长度的字典
3. PUT 与 DELETE
def put(url, data=None, **kwargs):
def delete():

