name: 使用TDD实现 description: 当实现错误修复、功能或任何适合测试先行开发的代码变更时使用。
TDD 实施指南
PairCoder 集成
在本项目中使用TDD进行实施时:
- 开始任务:
bpsai-pair task update TASK-XXX --status in_progress - 编写测试 在
tests/test_<模块>.py中 - 运行测试:
pytest tests/test_<模块>.py -v(预期为 红色/失败) - 实施代码 在
tools/cli/bpsai_pair/中 - 运行测试:
pytest tests/test_<模块>.py -v(预期为 绿色/通过) - 重构 如有需要,保持测试通过
- 完成任务:遵循“管理任务生命周期”技能完成两步操作
项目测试命令
# 运行特定测试
pytest tests/test_模块.py::test_函数 -v
# 运行所有测试
pytest
# 运行覆盖率测试
pytest --cov=tools/cli/bpsai_pair
# 仅运行失败的测试
pytest --lf
# 在首次失败时停止
pytest -x
# 显示打印输出
pytest -s
项目测试规范
- 测试文件:
tests/test_<模块>.py - 测试函数:
test_<函数>_<场景>_<预期>() - 使用
tests/conftest.py中的夹具 - 模拟外部服务(Trello API等)
代码检查
# 检查代码规范
ruff check .
# 自动修复
ruff check --fix .
运行所有检查
bpsai-pair ci # 在一个命令中运行测试 + 代码检查 + 类型检查
任务完成
测试通过后,遵循“管理任务生命周期”技能:
bpsai-pair ttask done TRELLO-XX --summary "..." --list "已部署/完成"bpsai-pair task update TASK-XXX --status done