# y-t **Repository Path**: yujing-tec/y-t ## Basic Information - **Project Name**: y-t - **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-11-26 - **Last Updated**: 2025-11-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # YTest - 全功能Python测试框架 [![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg)](https://python.org) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://github.com/ytest/ytest) YTest是一个从0到1构建的全功能Python测试框架,支持代码级单元测试、多协议接口测试、性能测试、E2E端到端Web&app&h5&pc等UI自动化测试,并集成Flask、Sanic、FastAPI、Tornado等后端开发环境。 ## ✨ 核心特性 ### 🎯 多类型测试支持 - **单元测试**: 基于unittest和pytest,支持代码级测试 - **API测试**: RESTful API、GraphQL、WebSocket等多协议支持 - **UI测试**: Selenium、Playwright等Web自动化测试 - **性能测试**: 负载测试、压力测试、基准测试 ### 🏗️ 企业级架构 - **分层设计**: 通用方法层、用例管理层、执行逻辑层、报告层、持久化层 - **设计模式**: 集成10+种核心设计模式(单例、工厂、观察者、策略等) - **事件驱动**: 完整的事件监听和处理机制 - **插件系统**: 支持自定义扩展和第三方插件 ### 🤖 AI智能功能 - **智能生成**: 基于API规范自动生成测试用例 - **结果分析**: AI驱动的测试结果分析和失败归因 - **性能优化**: 智能性能调优建议 - **日志聚类**: 自动日志分析和异常检测 ### 🚀 自动化模式支持 - **DDD**: 领域驱动设计测试 - **BDD**: 行为驱动开发测试 - **ATDD**: 验收测试驱动开发 - **KDT**: 关键字驱动测试 ### 🔧 集成支持 - **后端框架**: Flask、Sanic、FastAPI、Tornado - **CI/CD**: Jenkins、GitLab CI、GitHub Actions - **通知系统**: Email、Slack、Webhook - **数据库**: SQLite、MySQL、PostgreSQL ## 🚀 快速开始 ### 安装 ```bash pip install ytest ``` ### 创建项目脚手架 ```bash # 基础项目 ytest scaffold my_project # Web测试项目 ytest scaffold my_web_project --template web # API测试项目 ytest scaffold my_api_project --template api ``` ### 基础使用 ```python from ytest.core.framework import YTestFramework from ytest.core.base import UnitTest, APITest # 创建框架实例 framework = YTestFramework() # 运行测试 results = framework.run_tests( test_path='tests/', test_type='all', parallel=True, workers=4 ) # 生成报告 framework.generate_report('html', 'reports') ``` ### 命令行使用 ```bash # 运行测试 python main.py run tests/ --type api --parallel # 启动API服务 python main.py serve --port 8080 # 生成报告 python main.py report --format html --output report.html ``` ## 📖 使用示例 ### 单元测试 ```python from ytest.core.base import UnitTest class MathTest(UnitTest): def test_addition(self): result = 2 + 3 self.assert_equal(result, 5) def test_exception(self): with self.assert_raises(ValueError): int('invalid') ``` ### API测试 ```python from ytest.core.base import APITest class UserAPITest(APITest): def setup_test(self): self.base_url = 'https://api.example.com' self.headers = {'Authorization': 'Bearer token'} def test_get_users(self): response = self.get('/users') self.assert_equal(response.status_code, 200) self.assert_true(len(response.json()) > 0) ``` ### UI测试 ```python from ytest.core.base import UITest class LoginTest(UITest): def test_login(self): self.driver.get('https://example.com/login') username = self.driver.find_element('id', 'username') password = self.driver.find_element('id', 'password') login_btn = self.driver.find_element('id', 'login') username.send_keys('testuser') password.send_keys('password') login_btn.click() self.assert_true(self.driver.current_url.endswith('/dashboard')) ``` ### 性能测试 ```python from ytest.core.base import PerformanceTest class DatabasePerfTest(PerformanceTest): def test_query_performance(self): def query_operation(): # 执行数据库查询 return db.query("SELECT * FROM users") result = self.measure_performance( query_operation, iterations=100, max_time=5.0 ) self.assert_true(result['avg_time'] < 0.1) ``` ## 📊 项目结构 ``` y-t/ ├── ytest/ # 框架核心代码 │ ├── core/ # 核心模块 │ ├── utils/ # 工具模块 │ ├── runners/ # 运行器模块 │ ├── reporters/ # 报告模块 │ ├── storage/ # 存储模块 │ ├── patterns/ # 设计模式模块 │ ├── cli/ # 命令行模块 │ ├── api/ # API服务模块 │ └── ai/ # AI功能模块 ├── examples/ # 示例代码 ├── tests/ # 框架测试 ├── config/ # 配置文件 └── docs/ # 文档 ``` ## 🔧 配置系统 YTest支持灵活的YAML配置: ```yaml framework: name: "YTest" debug: false test: timeout: 30 retry_count: 3 parallel: enabled: true max_workers: 4 api: default_headers: Content-Type: "application/json" timeout: connect: 10 read: 30 ui: browser: type: "chrome" headless: true report: default_format: "html" output_dir: "./reports" ``` ## 🤖 AI功能 ### 智能测试生成 ```python from ytest.ai.generator import TestCaseGenerator generator = TestCaseGenerator() test_cases = generator.generate_from_api_spec(api_spec) ``` ### 结果分析 ```python from ytest.ai.analyzer import TestResultAnalyzer analyzer = TestResultAnalyzer() analysis = analyzer.analyze_results(test_results) ``` ## 📈 性能指标 - **启动时间**: < 2秒 - **测试发现**: 1000个测试文件 < 5秒 - **并行执行**: 4核机器支持100+并发测试 - **内存占用**: 基础运行 < 50MB ## 🔗 集成示例 ### Jenkins集成 ```groovy pipeline { agent any stages { stage('Test') { steps { sh 'ytest run tests/ --parallel' sh 'ytest report --format html --output reports/' publishHTML([ allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'reports', reportFiles: 'index.html', reportName: 'Test Report' ]) } } } } ``` ### Docker支持 ```dockerfile FROM python:3.9-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . RUN pip install -e . CMD ["ytest", "serve", "--host", "0.0.0.0"] ``` ## 📚 文档 - [完整文档](docs/README.md) - [API参考](docs/api.md) - [示例代码](examples/) - [最佳实践](docs/best-practices.md) ## 🤝 贡献 欢迎贡献代码!请查看 [贡献指南](CONTRIBUTING.md)。 ### 开发环境设置 ```bash git clone https://github.com/ytest/ytest.git cd ytest pip install -e ".[dev]" pytest tests/ ``` ## 📄 许可证 MIT License - 查看 [LICENSE](LICENSE) 文件了解详情。 ## 🙏 致谢 感谢所有为YTest框架做出贡献的开发者和用户! ## 📞 支持 - 📧 邮箱: support@ytest.dev - 💬 讨论: [GitHub Discussions](https://github.com/ytest/ytest/discussions) - 🐛 问题反馈: [GitHub Issues](https://github.com/ytest/ytest/issues) - 📖 文档: [https://ytest.readthedocs.io](https://ytest.readthedocs.io) --- ⭐ 如果YTest对你有帮助,请给我们一个星标!