名称: tdd-guide
描述: 支持测试生成、覆盖率分析与多框架的测试驱动开发工作流
触发器:
- 生成测试
- 分析覆盖率
- TDD 工作流
- 红绿重构
- Jest 测试
- Pytest 测试
- JUnit 测试
- 覆盖率报告
本技能支持测试驱动开发,能够生成测试用例、分析代码覆盖率,并指导在 Jest、Pytest、JUnit 和 Vitest 等框架下进行红-绿-重构工作流。
| 能力 | 描述 |
|---|---|
| 测试生成 | 将需求或代码转换为结构化的测试用例 |
| 覆盖率分析 | 解析 LCOV/JSON/XML 报告,识别覆盖缺口,并优先修复 |
| TDD 工作流 | 指导并验证红-绿-重构循环 |
| 框架适配器 | 为 Jest、Pytest、JUnit、Vitest、Mocha 生成测试 |
| 质量评分 | 评估测试隔离性、断言、命名规范,检测测试异味 |
| 夹具生成 | 创建真实的测试数据、模拟对象和工厂 |
test_generator.py 并附带需求npm test -- --coverage)coverage_analyzer.pytdd_workflow.py --phase red 进行验证tdd_workflow.py --phase green 进行验证| 工具 | 用途 | 用法示例 |
|---|---|---|
test_generator.py |
根据代码/需求生成测试用例 | python scripts/test_generator.py --input source.py --framework pytest |
coverage_analyzer.py |
解析和分析覆盖率报告 | python scripts/coverage_analyzer.py --report lcov.info --threshold 80 |
tdd_workflow.py |
指导红-绿-重构循环 | python scripts/tdd_workflow.py --phase red --test test_auth.py |
framework_adapter.py |
在不同测试框架间转换测试 | python scripts/framework_adapter.py --from jest --to pytest |
fixture_generator.py |
生成测试数据和模拟对象 | python scripts/fixture_generator.py --entity User --count 5 |
metrics_calculator.py |
计算测试质量指标 | python scripts/metrics_calculator.py --tests tests/ |
format_detector.py |
检测语言和框架 | python scripts/format_detector.py --file source.ts |
output_formatter.py |
为 CLI/桌面/CI 格式化输出 | python scripts/output_formatter.py --format markdown |
对于测试生成:
- 源代码(文件路径或粘贴的内容)
- 目标框架(Jest、Pytest、JUnit、Vitest)
- 覆盖范围(单元测试、集成测试、边界情况)
对于覆盖率分析:
- 覆盖率报告文件(LCOV、JSON 或 XML 格式)
- (可选)用于上下文的源代码
- (可选)目标阈值百分比
对于 TDD 工作流:
- 功能需求或用户故事
- 当前阶段(红、绿、重构)
- 测试代码和实现状态
| 范围 | 详情 |
|---|---|
| 侧重单元测试 | 集成测试和端到端测试需要不同的模式 |
| 静态分析 | 无法执行测试或测量运行时行为 |
| 语言支持 | 最适合 TypeScript、JavaScript、Python、Java |
| 报告格式 | 仅支持 LCOV、JSON、XML;其他格式需要转换 |
| 生成的测试 | 提供脚手架;复杂逻辑需要人工审查 |
何时使用其他工具:
- 端到端测试:Playwright、Cypress、Selenium
- 性能测试:k6、JMeter、Locust
- 安全测试:OWASP ZAP、Burp Suite