lhl
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
  • python

  • leetcode

  • 软件测试

    • 项目开发模型
    • Bug的理解
    • 测试用例
    • 接口测试
      • 认知
      • postman 的使用
      • 接口自动化测试
    • web自动化测试
    • Pytest
  • Git

  • linux

  • 产品

  • MySql

  • docker

  • test
2023-07-22
目录

接口自动化测试

# 接口测试

# 认知

# 软件架构

大体经历了 单体结构 ->-> 主从结构 ->-> 微服务结构 ->-> 微服务再细分下的负载均衡结构

# 跟功能测试的区别

功能测试主要是围绕页面的功能来进行测试用例的设计和执行, 通过页面的反馈来验证是否功能实现的准确性

接口测试则是根据接口协议和接口参数来进行测试用例的设计和执行, 通过接口返回的数据来验证返回数据的准确性。

# postman 的使用

环境变量设置 (opens new window)
postman 前置处理&&后置处理 (opens new window)

# 接口自动化测试

# 接口自动化测试用例字段设计

  • 用例编号
  • 用例标题
  • 请求接口类别
  • 请求地址
  • 输入数据
  • 数据格式
  • 请求方式
  • 是否需要登录
  • 期望结果

ps: 测试用例可以选用 excel 或者 mysql 进行存储

# 接口测试栗子(用例存储在mysql)


+----------------+--------------+------+-----+---------+-------+
| Field          | Type         | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| id             | varchar(255) | YES  |     | NULL    |       |
| name           | varchar(255) | YES  |     | NULL    |       |
| interface_type | varchar(255) | YES  |     | NULL    |       |
| request_url    | varchar(255) | YES  |     | NULL    |       |
| request_type   | varchar(255) | YES  |     | NULL    |       |
| need_login     | varchar(255) | YES  |     | NULL    |       |
| data           | varchar(255) | YES  |     | NULL    |       |
| data_type      | varchar(255) | YES  |     | NULL    |       |
| expect_result  | varchar(255) | YES  |     | NULL    |       |
+----------------+--------------+------+-----+---------+-------+

# mysql 直接查询 && pytest

def get_sql_conn():
    db_info = {
        "host": "localhost",
        "user": "root",
        "password": "****",
        "database": "test",
        "charset": "utf8"
    }
    conn = pymysql.connect(**db_info)
    return conn


def get_data(interface_type):

    conn = get_sql_conn()
    sql = "select * from test where interface_type = '{}' ".format(interface_type)
    cursor = conn.cursor()
    cursor.execute(sql)
    res = cursor.fetchall()
    return res
@pytest.fixture(params=get_data("登录"))
def get_db_data_login(request):
    return request.param


def test_login(get_db_data_login):
    # print(get_db_login_data)
    id = get_db_data_login[0]
    name = get_db_data_login[1]
    interface_type = get_db_data_login[2]
    request_url = get_db_data_login[3]
    request_type = get_db_data_login[4]
    need_login = get_db_data_login[5]
    data = get_db_data_login[6]
    data_type = get_db_data_login[7]
    expect_result = get_db_data_login[8]

    # print('data type %s,data %s' % (type(data), data))
    if request_type.upper() == 'GET':
        res = requests.get(url + request_url, json.loads(data))
        print(res.text)
        assert res.status_code == 200
        assert int(expect_result) == int(json.loads(res.text)['status'])
    elif request_type.upper() == 'POST':
        pass

# pandas 执行查询 && pytest

@pytest.fixture(params=get_data_pandas('登录'))
def get_db_pandas_data_login(request):
    return request.param


def test_login_pandas(get_db_pandas_data_login):
    request_url = get_db_pandas_data_login['request_url']
    method = get_db_pandas_data_login['request_type']
    data = get_db_pandas_data_login['data']
    expect_result = get_db_pandas_data_login['expect_result']


    if method.upper() == 'GET':
        res = requests.get(url+request_url, json.loads(data))
        assert res.status_code == 200
        assert int(json.loads(res.text)['status']) == int(expect_result)
    elif method.upper == 'POST':
        pass
def get_data_pandas(interface_type):

    conn = get_sql_conn()
    sql = "select * from test where interface_type = '{}' ".format(interface_type)
    df = pd.read_sql(sql, conn)
    # row 行, colN 列名
    # pandas 返回的数据是不符合我们需要的,所以我们需要重新进行封装
    final_res = []
    for row in df.index:
        tempdata = {}
        for colN in df.iloc[[row]]:
            tempdata[colN] = df[colN][row]
        final_res.append(tempdata)

    print(final_res)
    return final_res

测试用例
web自动化测试

← 测试用例 web自动化测试→

最近更新
01
lhl learn notes
02
filter
06-09
03
decorator
06-09
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式