# api_test_demo **Repository Path**: rainaReal/api_test_demo ## Basic Information - **Project Name**: api_test_demo - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-09 - **Last Updated**: 2025-07-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API 接口自动化测试框架 基于 Python + pytest + requests + allure 的接口自动化测试框架,支持数据驱动、多环境配置、自动化报告等特性。 ## 框架特点 ### 1. 分层设计 ```mermaid graph TB TestCases[测试用例层] --> Core[核心组件层] TestCases --> Utils[工具层] Core --> Config[配置层] Utils --> Config subgraph 测试用例层 TC1[认证测试] --> Common1[通用治理] TC2[用户管理] --> Common1 TC3[个人信息] --> Common1 end subgraph 核心组件层 API[接口请求] --> Assert[断言处理] API --> Log[日志处理] end subgraph 工具层 DH[数据处理] --> Common2[通用工具] end subgraph 配置层 ENV[环境配置] --> Global[全局配置] end ``` ### 2. 技术架构 ```mermaid flowchart LR CSV[测试数据\nCSV] --> Parser[数据解析器] Parser --> TestCase[测试用例] TestCase --> ApiClient[请求客户端] ApiClient --> Response[响应处理] Response --> Assert[断言处理] Assert --> Report[测试报告] Config[配置管理] --> ApiClient Config --> Parser Logger[日志记录] --> ApiClient Logger --> Assert ``` ### 3. 执行流程 ```mermaid sequenceDiagram participant TC as 测试用例 participant DH as 数据处理 participant API as 接口请求 participant Log as 日志记录 participant Assert as 断言处理 TC->>DH: 加载测试数据 DH->>TC: 返回处理后的数据 TC->>API: 发送请求 API->>Log: 记录请求信息 API->>API: 执行请求 API->>Log: 记录响应信息 API->>TC: 返回响应 TC->>Assert: 验证响应 Assert->>Log: 记录断言结果 ``` ## 目录结构 ``` api_autotest/ ├── conftest.py # pytest配置文件 ├── pytest.ini # pytest配置 ├── requirements.txt # 项目依赖 ├── config/ # 配置管理 │ ├── config.yaml # 环境配置文件 │ └── config.py # 配置读取类 ├── core/ # 核心组件 │ ├── api_client.py # 请求客户端 │ ├── logger.py # 日志工具 │ └── assertions.py # 断言工具 ├── data/ # 测试数据 │ └── test_cases.csv # 测试用例数据 ├── testcases/ # 测试用例 │ ├── test_auth.py # 认证测试 │ └── test_user.py # 用户管理测试 └── utils/ # 工具类 ├── data_handler.py # 数据处理 └── common.py # 通用工具 ``` ## 核心功能 ### 1. 数据驱动 - CSV 格式测试用例管理 - 支持参数化测试 - 灵活的数据处理机制 ### 2. 请求处理 - 封装的请求客户端 - 支持会话管理 - 灵活的请求配置 ### 3. 断言机制 - 多层级断言支持 - 详细的断言信息 - 自定义断言方法 ### 4. 日志记录 - 分级日志管理 - 详细的请求/响应记录 - 格式化的日志输出 ### 5. 报告生成 - Allure 报告支持 - 测试步骤记录 - 失败用例分析 ## 测试用例组织