# apitest-skill **Repository Path**: automatrix/apitest-skill ## Basic Information - **Project Name**: apitest-skill - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-05 - **Last Updated**: 2026-03-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API Testing Skill 基于JSON的API接口自动化测试框架,支持从Swagger/OpenAPI生成测试用例,一键运行测试并生成报告。 ## 功能特性 - 📄 **JSON格式用例** - 纯JSON配置,无需编写代码 - 🔄 **Swagger导入** - 自动从Swagger/OpenAPI生成测试用例 - 🏷️ **模块化管理** - 按模块组织用例,支持标签筛选 - 🔗 **变量传递** - 支持用例间变量提取和传递 - 📝 **多格式报告** - 支持HTML/JSON/JUnit/Allure报告 - 🌐 **多环境支持** - 支持dev/staging/prod等多环境配置 - 🪝 **前置/后置** - 支持setup/teardown操作 ## 快速开始 ### 1. 安装依赖 ```bash pip install -r requirements.txt ``` ### 2. 初始化项目 ```bash python scripts/init_project.py --name my-api-test cd my-api-test ``` ### 3. 配置环境 编辑 `env/dev.json`: ```json { "name": "dev", "base_url": "http://localhost:8080", "variables": { "username": "test_user", "password": "test_pass" } } ``` ### 4. 编写用例 创建 `testcases/user/login.json`: ```json { "id": "user_login_001", "name": "用户登录-正常场景", "module": "user", "tags": ["login", "smoke"], "enabled": true, "request": { "method": "POST", "url": "${base_url}/api/v1/user/login", "headers": { "Content-Type": "application/json" }, "body": { "username": "${username}", "password": "${password}" } }, "assertions": [ { "type": "status_code", "expected": 200 }, { "type": "json_path", "path": "$.code", "expected": 0 } ] } ``` ### 5. 运行测试 ```bash # 运行所有测试 python scripts/run_test.py --config config.json # 运行指定模块 python scripts/run_test.py --module user # 运行指定用例 python scripts/run_test.py --case testcases/user/login.json ``` ### 6. 生成报告 ```bash python scripts/generate_report.py \ --input reports/report_20240304_153022.json \ --format html,json ``` ## 从Swagger生成用例 ```bash # 从URL python scripts/swagger_parser.py \ --url http://api.example.com/swagger.json \ --output ./testcases # 从文件 python scripts/swagger_parser.py \ --file ./swagger.json \ --output ./testcases ``` ## 目录结构 ``` api-testing/ ├── SKILL.md # 完整规范文档 ├── README.md # 本文件 ├── requirements.txt # Python依赖 ├── scripts/ # 核心脚本 │ ├── init_project.py # 项目初始化 │ ├── run_test.py # 测试执行 │ ├── swagger_parser.py # Swagger解析 │ ├── generate_report.py # 报告生成 │ └── validate.py # 用例验证 ├── templates/ # 模板文件 │ ├── case_template.json # 用例模板 │ ├── suite_template.json # 套件模板 │ ├── config_template.json # 配置模板 │ └── env_template.json # 环境模板 └── examples/ # 示例用例 ├── user_login.json ├── user_login_fail.json └── order_create.json ``` ## 完整规范 详见 [SKILL.md](SKILL.md) 文档,包含: - JSON用例完整规范 - 断言类型说明 - 变量和函数 - 前置/后置操作 - 测试套件配置 - 报告格式说明 ## License MIT