Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interface Test Platform

基于 Python + Pytest 的接口自动化测试框架。

项目介绍

本项目是一个面向测试开发学习和实际接口测试场景的自动化测试平台。

通过 Python 搭建接口自动化测试框架,实现了接口请求封装、测试数据管理、配置管理、日志记录以及自动化测试报告生成。

项目采用分层设计,提高代码复用性和可维护性。


技术栈

  • Python
  • Pytest
  • Requests
  • PyYAML
  • Allure Report

项目结构

interface-test-platform
│
├── app
│   └── main.py                 # 模拟接口服务
│
├── common
│   ├── request.py              # HTTP请求封装
│   ├── logger.py               # 日志模块
│   └── __init__.py
│
├── config
│   └── config.yaml             # 环境配置文件
│
├── data
│   └── login.yaml              # 测试数据文件
│
├── testcases
│   └── test_login.py           # 登录接口测试用例
│
├── logs
│   └── test.log                # 测试日志
│
├── reports
│   ├── allure-results          # Allure测试数据
│   └── allure-report           # 测试报告
│
├── requirements.txt            # 项目依赖
│
└── README.md                   # 项目说明

已实现功能

1. 接口请求封装

对 Requests 进行二次封装,实现统一的 HTTP 请求调用。

支持:

  • GET请求
  • POST请求
  • 请求参数传递
  • 返回结果处理

2. 测试数据管理

使用 YAML 文件管理测试数据,实现:

  • 测试数据与代码分离
  • 参数化测试
  • 多场景测试

3. 自动化测试执行

基于 Pytest 实现:

  • 测试用例管理
  • 参数化执行
  • 断言校验

4. 日志记录

实现测试过程日志记录,包括:

  • 请求地址
  • 请求参数
  • 返回结果
  • 异常信息

5. 测试报告生成

集成 Allure,实现:

  • 测试结果可视化
  • 测试步骤展示
  • 测试通过率统计

环境要求

Python >= 3.10

安装依赖:

pip install -r requirements.txt

使用方法

1. 启动接口服务

运行:

python app/main.py

启动成功后:

Running on http://127.0.0.1:5000

2. 执行测试

运行:

pytest

3. 生成 Allure 测试数据

pytest --alluredir=reports/allure-results

4. 生成测试报告

allure generate reports/allure-results -o reports/allure-report --clean

5. 打开测试报告

allure open reports/allure-report

测试结果

当前已完成登录接口自动化测试:

  • 测试接口:登录接口
  • 测试场景:正常登录
  • 测试用例数量:3
  • 测试结果:全部通过

项目亮点

  • 采用接口自动化测试分层设计
  • 实现测试代码与测试数据分离
  • 封装公共请求方法,提高代码复用率
  • 集成日志系统,方便问题定位
  • 集成 Allure 生成可视化测试报告

后续优化方向

  • 增加更多业务接口测试
  • 增加异常场景测试
  • 增加数据库校验
  • 集成 Jenkins 持续集成
  • 接入接口定时自动化执行

About

Python interface automation testing framework based on Pytest

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages