← 返回 Skills 市场
OpenClaw TDD
作者
michealxie001
· GitHub ↗
· v1.0.0
· MIT-0
132
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install openclaw-tdd
功能描述
Test-Driven Development assistant. Generates test cases from code or specifications, runs tests, tracks coverage, and guides the red-green-refactor cycle. Su...
使用说明 (SKILL.md)
TDD (Test-Driven Development)
测试驱动开发助手,从代码或规格生成测试用例,运行测试,追踪覆盖率,引导红-绿-重构循环。
Version: 1.0
Features: 测试生成、测试运行、覆盖率追踪、TDD 工作流
Quick Start
1. 为函数生成测试
# 为单个函数生成测试
python3 scripts/main.py generate --function "calculate_total" --file src/cart.py
# 为整个模块生成测试
python3 scripts/main.py generate --file src/cart.py --output tests/test_cart.py
2. 运行测试
# 运行所有测试
python3 scripts/main.py run
# 运行特定测试文件
python3 scripts/main.py run tests/test_cart.py
# 持续监听模式
python3 scripts/main.py run --watch
3. TDD 循环
# 开始 TDD 会话
python3 scripts/main.py cycle --file src/new_feature.py
# 检查当前状态
python3 scripts/main.py status
4. 覆盖率报告
# 生成覆盖率报告
python3 scripts/main.py coverage
# 查看未覆盖的代码
python3 scripts/main.py coverage --uncovered
Commands
| 命令 | 说明 | 示例 |
|---|---|---|
generate |
生成测试 | generate --file src/x.py |
run |
运行测试 | run tests/ |
cycle |
TDD 循环 | cycle --file src/x.py |
status |
查看状态 | status |
coverage |
覆盖率报告 | coverage --html |
mutant |
变异测试 | mutant src/ |
Test Generation
从函数签名生成
# src/calculator.py
def calculate_discount(price: float, rate: float) -> float:
"""Calculate discounted price"""
return price * (1 - rate)
生成的测试:
# tests/test_calculator.py
def test_calculate_discount():
# Normal case
assert calculate_discount(100.0, 0.2) == 80.0
# Edge cases
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
# Negative tests
with pytest.raises(ValueError):
calculate_discount(-100.0, 0.2)
支持的测试框架
| 语言 | 框架 | 自动检测 |
|---|---|---|
| Python | pytest | ✅ |
| Python | unittest | ✅ |
| JavaScript | Jest | ✅ |
| Go | testing | ✅ |
TDD Cycle
红-绿-重构循环
$ python3 scripts/main.py cycle --file src/calculator.py
🔄 TDD Cycle for src/calculator.py
================================
🔴 RED: Write a failing test
Generated: tests/test_calculator.py
Add your test case and run: tdd run
$ # 编辑测试文件...
$ python3 scripts/main.py run
🔴 Test FAILED (expected)
💚 GREEN: Make it pass
Implement the function to pass the test
$ # 编辑实现...
$ python3 scripts/main.py run
💚 Test PASSED
♻️ REFACTOR: Improve the code
Run: tdd run
Check coverage: tdd coverage
$ python3 scripts/main.py run
♻️ All tests pass, ready to refactor
状态追踪
$ python3 scripts/main.py status
📊 TDD Status
=============
Current Phase: GREEN
Last Run: 2026-04-01 18:30:00
Tests: 5 passed, 0 failed
Coverage: 87%
Next: Refactor or add new test
Coverage
基本报告
python3 scripts/main.py coverage
输出:
📊 Coverage Report
==================
Total: 87%
src/calculator.py 95% ✅
src/discount.py 72% ⚠️
src/utils.py 45% 🔴
未覆盖代码
python3 scripts/main.py coverage --uncovered
输出:
🔍 Uncovered Lines
==================
src/discount.py:45-52 calculate_bulk_discount
src/utils.py:12-30 validate_email
HTML 报告
python3 scripts/main.py coverage --html --output coverage_report/
Configuration
.tdd.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
}
}
Examples
场景 1:为新功能写测试
# 1. 创建新文件
touch src/payment.py
# 2. 生成测试框架
python3 scripts/main.py generate --file src/payment.py
# 3. 编辑测试(让它失败)
# tests/test_payment.py
# 4. 运行测试(应该失败)
python3 scripts/main.py run
# 5. 实现功能(让它通过)
# src/payment.py
# 6. 运行测试(应该通过)
python3 scripts/main.py run
# 7. 重构并确保测试仍通过
python3 scripts/main.py run
场景 2:提高覆盖率
# 1. 查看当前覆盖率
python3 scripts/main.py coverage
# 2. 找到未覆盖的代码
python3 scripts/main.py coverage --uncovered
# 3. 为未覆盖的函数生成测试
python3 scripts/main.py generate --function "uncovered_func" --file src/utils.py
# 4. 再次检查覆盖率
python3 scripts/main.py coverage
场景 3:回归测试
# 修复 bug 前,先写测试
python3 scripts/main.py generate --function "buggy_function" --file src/auth.py
# 确认测试失败(复现 bug)
python3 scripts/main.py run
# 修复 bug
# ...
# 确认测试通过
python3 scripts/main.py run
Mutation Testing
测试测试的质量:
python3 scripts/main.py mutant src/
原理:
- 自动修改代码(变异)
- 运行测试
- 如果测试通过,说明测试不够严格
输出:
🧬 Mutation Testing
===================
Mutants: 45
Killed: 42 (93%) ✅
Survived: 3 (7%) ⚠️
Survived mutants:
- src/calculator.py:23 (changed + to -)
Test didn't catch this!
CI/CD 集成
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Tests
run: python3 skills/tdd/scripts/main.py run
- name: Coverage Check
run: python3 skills/tdd/scripts/main.py coverage --fail-under 80
Files
skills/tdd/
├── SKILL.md # 本文件
└── scripts/
├── main.py # ⭐ 统一入口
├── generator.py # 测试生成器
├── runner.py # 测试运行器
└── coverage.py # 覆盖率追踪
Roadmap
- 测试生成(Python)
- 测试运行(pytest/unittest)
- 覆盖率报告
- TDD 循环引导
- 变异测试
- JavaScript/Go 支持
- AI 辅助测试生成
安全使用建议
This skill appears to do what it claims. Important safety notes before installing/using: (1) Running tests will execute the project's code — do not run on untrusted repositories or without sandboxing (use containers or VMs). (2) The generator can write/overwrite test files in your repo; review generated tests before committing. (3) The scripts call pytest/unittest via subprocess and write/read JSON to /tmp; concurrent runs may conflict. Recommended practice: run in an isolated environment (virtualenv/container), inspect generated files, and ensure test execution privileges and network access are limited for untrusted code.
功能分析
Type: OpenClaw Skill
Name: openclaw-tdd
Version: 1.0.0
The skill bundle provides a legitimate set of TDD (Test-Driven Development) utilities including test generation, execution, and coverage reporting. It uses standard Python libraries (ast, subprocess) to perform its tasks, and while it executes shell commands via subprocess to run tests (e.g., in scripts/runner.py and scripts/coverage.py), this behavior is essential for its stated purpose and implemented using safe practices (argument lists rather than shell=True). No evidence of data exfiltration, malicious persistence, or prompt injection was found in the code or the SKILL.md instructions.
能力评估
Purpose & Capability
The name/description (TDD assistant: generate tests, run tests, track coverage, guide cycle) matches the included scripts (generator.py, runner.py, coverage.py, main.py) and the SKILL.md examples. No unrelated binaries, env vars, or external services are requested.
Instruction Scope
SKILL.md instructs running the bundled scripts (python3 scripts/main.py ...) which in turn run pytest/unittest and create or print test files and coverage reports. This is within purpose, but the runner executes the project's test code (via pytest/unittest) and the generator writes test files into the repo — meaning arbitrary project code will be executed when you run tests and files may be created/overwritten. That's expected for a TDD tool but is a security consideration when used on untrusted code.
Install Mechanism
No install spec; this is an instruction + script bundle, so nothing is downloaded or installed by the skill itself. The scripts call system-installed Python and testing tools (pytest/unittest/coverage), which is appropriate for this tool.
Credentials
The skill declares no environment variables, credentials, or config paths. The code uses /tmp for intermediate JSON reports and reads/writes files in the provided project root — behavior consistent with coverage/test tooling and proportional to the stated purpose.
Persistence & Privilege
always is false and the skill does not attempt to persist configuration outside the project (it writes tests and htmlcov under project paths, and uses /tmp for ephemeral reports). It does not modify other skills or global agent settings.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install openclaw-tdd - 安装完成后,直接呼叫该 Skill 的名称或使用
/openclaw-tdd触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Test-Driven Development assistant with test generation, test running, and coverage tracking
元数据
常见问题
OpenClaw TDD 是什么?
Test-Driven Development assistant. Generates test cases from code or specifications, runs tests, tracks coverage, and guides the red-green-refactor cycle. Su... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 132 次。
如何安装 OpenClaw TDD?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install openclaw-tdd」即可一键安装,无需额外配置。
OpenClaw TDD 是免费的吗?
是的,OpenClaw TDD 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
OpenClaw TDD 支持哪些平台?
OpenClaw TDD 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 OpenClaw TDD?
由 michealxie001(@michealxie001)开发并维护,当前版本 v1.0.0。
推荐 Skills