Install
openclaw skills install auto-test自动生成单元测试。分析代码逻辑,自动生成 pytest (Python)、JUnit (Java)、Jest (JavaScript) 等测试框架的测试用例。支持覆盖率报告生成。
openclaw skills install auto-test智能自动生成单元测试,提升代码覆盖率,减少手动测试工作量。
# 分析项目并生成测试
python3 scripts/generate-tests.py --path /path/to/project --framework pytest
# 生成覆盖率报告
python3 scripts/generate-tests.py --path . --coverage --output coverage.html
# 仅分析不生成(预览)
python3 scripts/generate-tests.py --path . --dry-run
| 参数 | 说明 | 默认 |
|---|---|---|
--path | 项目路径 | . |
--framework | 测试框架 | pytest |
--coverage | 生成覆盖率 | false |
--output | 输出文件/目录 | ./tests/ |
--dry-run | 仅预览 | false |
--exclude | 排除目录 | node_modules,vendor,target |
| 语言 | 框架 | 状态 |
|---|---|---|
| Python | pytest, unittest | ✅ 完整 |
| Java | JUnit 4/5, TestNG | ✅ 完整 |
| JavaScript/TypeScript | Jest, Vitest, Mocha | ✅ 完整 |
| Go | testing | ✅ 完整 |
| Rust | cargo test | ✅ 完整 |
| C# | NUnit, xUnit | 🚧 开发中 |
# 生成的测试 (pytest)
def test_process_order_valid():
"""测试有效订单处理"""
order = Order(id=1, items=[...], total=100.0)
result = process_order(order)
assert result.status == "completed"
assert result.processed_at is not None
def test_process_order_invalid_total():
"""测试无效订单总金额"""
order = Order(id=2, items=[...], total=-10.0)
with pytest.raises(InvalidOrderError):
process_order(order)
def test_process_order_empty_items():
"""测试空购物车"""
order = Order(id=3, items=[], total=0.0)
with pytest.raises(EmptyCartError):
process_order(order)
pre-commit hook,提交前自动生成测试--dry-run 预览,避免覆盖现有测试