Test-Driven Development assistant. Generates test cases from code or specifications, runs tests, tracks coverage, and guides the red-green-refactor cycle. Supports pytest, unittest, jest, and go test.
测试驱动开发助手,从代码或规格生成测试用例,运行测试,追踪覆盖率,引导红-绿-重构循环。
版本:1.0
功能:测试生成、测试运行、覆盖率追踪、TDD 工作流
bash
bash
bash
bash
| 命令 | 说明 | 示例 |
|---|---|---|
| generate | 生成测试 | generate --file src/x.py |
| run |
python
生成的测试:
python
# 边界情况
assert calculate_discount(0.0, 0.2) == 0.0
assert calculate_discount(100.0, 0.0) == 100.0
assert calculate_discount(100.0, 1.0) == 0.0
# 异常测试
with pytest.raises(ValueError):
calculate_discount(-100.0, 0.2)
| 语言 | 框架 | 自动检测 |
|---|---|---|
| Python | pytest | ✅ |
| Python |
bash
$ python3 scripts/main.py cycle --file src/calculator.py
🔄 TDD 循环 - src/calculator.py
================================
🔴 红色:编写一个会失败的测试
已生成:tests/test_calculator.py
添加你的测试用例并运行:tdd run
$ # 编辑测试文件...
$ python3 scripts/main.py run
🔴 测试失败(预期)
💚 绿色:让它通过
实现函数以通过测试
$ # 编辑实现...
$ python3 scripts/main.py run
💚 测试通过
♻️ 重构:改进代码
运行:tdd run
检查覆盖率:tdd coverage
$ python3 scripts/main.py run
♻️ 所有测试通过,准备重构
bash
$ python3 scripts/main.py status
📊 TDD 状态
=============
当前阶段:绿色
上次运行:2026-04-01 18:30:00
测试:5 通过,0 失败
覆盖率:87%
下一步:重构或添加新测试
bash
python3 scripts/main.py coverage
输出:
📊 覆盖率报告
==================
总计:87%
src/calculator.py 95% ✅
src/discount.py 72% ⚠️
src/utils.py 45% 🔴
bash
python3 scripts/main.py coverage --uncovered
输出:
🔍 未覆盖的行
==================
src/discount.py:45-52 calculatebulkdiscount
src/utils.py:12-30 validate_email
bash
python3 scripts/main.py coverage --html --output coverage_report/
.tdd.json:
json
{
framework: pytest,
test_dir: tests,
source_dir: src,
coverage: {
threshold: 80,
exclude: [tests/, vendor/]
},
generate: {
edge_cases: true,
error_cases: true,
property_tests: false
}
}
bash
bash
bash
测试测试的质量:
bash
python3 scripts/main.py mutant src/
原理:
输出:
🧬 变异测试
===================
变异体:45
已杀死:42(93%)✅
存活:3(7%)⚠️
存活的变异体:
yaml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 运行测试
run: python3 skills/tdd/scripts/main.py run
- name: 覆盖率检查
run: python3 skills/tdd/scripts/main.py coverage --fail-under 80
skills/tdd/
├── SKILL.md # 本文件
└── scripts/
├── main.py # ⭐ 统一入口
├── generator.py # 测试生成器
├── runner.py # 测试运行器
└── coverage.py # 覆盖率追踪
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 openclaw-tdd-1775890441 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-tdd-1775890441 技能
skillhub install openclaw-tdd-1775890441
文件大小: 12 KB | 发布时间: 2026-4-12 10:51