test-updates
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
- Overview
- Core Philosophy
- What It Is
- Quick Start
- Quick Checklist for First Time Use
- detailed Test Update
- Targeted Test Updates
- TDD for New Features
- Using the Scripts Directly
- When to Use It
- Workflow Integration
- Phase 1: Discovery
- Phase 2: Strategy
- Phase 3: Implementation
- Phase 4: Validation
- Quality Assurance
- Examples
- BDD-Style Test Generation
- Test Enhancement
- Integration with Existing Skills
- Success Metrics
- Troubleshooting FAQ
- Common Issues
- Performance Tips
- Getting Help
Test Updates and Maintenance
测试更新与维护
Overview
概述
detailed test management system that applies TDD/BDD principles to maintain, generate, and enhance tests across codebases. This skill practices what it preaches - it uses TDD principles for its own development and serves as a living example of best practices.
这是一个遵循TDD/BDD原则的精细化测试管理系统,用于在代码库中维护、生成和优化测试。该技能以身作则——它自身的开发就采用了TDD原则,是最佳实践的鲜活示例。
Core Philosophy
核心理念
- RED-GREEN-REFACTOR: Strict adherence to TDD cycle
- Behavior-First: BDD patterns that describe what code should do
- Meta Dogfooding: The skill's own tests demonstrate the principles it teaches
- Quality Gates: detailed validation before considering tests complete
- RED-GREEN-REFACTOR(红-绿-重构):严格遵循TDD周期
- 行为优先:采用BDD模式描述代码应实现的功能
- 自我验证:该技能自身的测试展示了它所传授的原则
- 质量关卡:在认定测试完成前进行精细化验证
What It Is
功能介绍
A modular test management system that:
- Discovers what needs testing or updating
- Generates tests following TDD principles
- Enhances existing tests with BDD patterns
- Validate test quality through multiple lenses
这是一个模块化的测试管理系统,具备以下能力:
- 发现需要测试或更新的内容
- 遵循TDD原则生成测试
- 用BDD模式优化现有测试
- 从多个维度验证测试质量
Quick Start
快速开始
Quick Checklist for First Time Use
首次使用快速检查清单
- validate pytest is installed ()
pip install pytest - Have your source code in or similar directory
src/ - Create a directory if it doesn't exist
tests/ - Run first to understand changes
Skill(sanctum:git-workspace-review) - Start with for focused updates
Skill(test-updates) --target <specific-module>
- 确认已安装pytest(执行)
pip install pytest - 源代码放在或类似目录下
src/ - 若不存在目录则创建它
tests/ - 先运行了解代码变更
Skill(sanctum:git-workspace-review) - 执行开始定向更新
Skill(test-updates) --target <特定模块>
detailed Test Update
全面测试更新
bash
undefinedbash
undefinedRun full test update workflow
运行完整的测试更新工作流
Skill(test-updates)
**Verification:** Run `pytest -v` to verify tests pass.Skill(test-updates)
**验证方式:** 执行`pytest -v`确认测试通过。Targeted Test Updates
定向测试更新
bash
undefinedbash
undefinedUpdate tests for specific paths
更新特定路径下的测试
Skill(test-updates) --target src/sanctum/agents
Skill(test-updates) --target tests/test_commit_messages.py
**Verification:** Run `pytest -v` to verify tests pass.Skill(test-updates) --target src/sanctum/agents
Skill(test-updates) --target tests/test_commit_messages.py
**验证方式:** 执行`pytest -v`确认测试通过。TDD for New Features
新功能的TDD实践
bash
undefinedbash
undefinedApply TDD to new code
对新代码应用TDD
Skill(test-updates) --tdd-only --target new_feature.py
**Verification:** Run `pytest -v` to verify tests pass.Skill(test-updates) --tdd-only --target new_feature.py
**验证方式:** 执行`pytest -v`确认测试通过。Using the Scripts Directly
直接使用脚本
Human-Readable Output:
bash
undefined人类可读输出:
bash
undefinedAnalyze test coverage gaps
分析测试覆盖缺口
python plugins/sanctum/skills/test-updates/scripts/test_analyzer.py --scan src/
python plugins/sanctum/skills/test-updates/scripts/test_analyzer.py --scan src/
Generate test scaffolding
生成测试脚手架
python plugins/sanctum/skills/test-updates/scripts/test_generator.py
--source src/my_module.py --style pytest_bdd
--source src/my_module.py --style pytest_bdd
python plugins/sanctum/skills/test-updates/scripts/test_generator.py
--source src/my_module.py --style pytest_bdd
--source src/my_module.py --style pytest_bdd
Check test quality
检查测试质量
python plugins/sanctum/skills/test-updates/scripts/quality_checker.py
--validate tests/test_my_module.py
--validate tests/test_my_module.py
**Verification:** Run `pytest -v` to verify tests pass.
**Programmatic Output (for Claude Code):**
```bashpython plugins/sanctum/skills/test-updates/scripts/quality_checker.py
--validate tests/test_my_module.py
--validate tests/test_my_module.py
**验证方式:** 执行`pytest -v`确认测试通过。
**供Claude Code使用的程序化输出:**
```bashGet JSON output for programmatic parsing - test_analyzer
获取用于程序化解析的JSON输出 - test_analyzer
python plugins/sanctum/skills/test-updates/scripts/test_analyzer.py
--scan src/ --output-json
--scan src/ --output-json
python plugins/sanctum/skills/test-updates/scripts/test_analyzer.py
--scan src/ --output-json
--scan src/ --output-json
Returns:
返回结果:
{
{
"success": true,
"success": true,
"data": {
"data": {
"source_files": ["src/module.py", ...],
"source_files": ["src/module.py", ...],
"test_files": ["tests/test_module.py", ...],
"test_files": ["tests/test_module.py", ...],
"uncovered_files": ["module_without_tests", ...],
"uncovered_files": ["module_without_tests", ...],
"coverage_gaps": [{"file": "...", "reason": "..."}]
"coverage_gaps": [{"file": "...", "reason": "..."}]
}
}
}
}
Get JSON output - test_generator
获取JSON输出 - test_generator
python plugins/sanctum/skills/test-updates/scripts/test_generator.py
--source src/my_module.py --output-json
--source src/my_module.py --output-json
python plugins/sanctum/skills/test-updates/scripts/test_generator.py
--source src/my_module.py --output-json
--source src/my_module.py --output-json
Returns:
返回结果:
{
{
"success": true,
"success": true,
"data": {
"data": {
"test_file": "path/to/test_my_module.py",
"test_file": "path/to/test_my_module.py",
"source_file": "src/my_module.py",
"source_file": "src/my_module.py",
"style": "pytest_bdd",
"style": "pytest_bdd",
"fixtures_included": true,
"fixtures_included": true,
"edge_cases_included": true,
"edge_cases_included": true,
"error_cases_included": true
"error_cases_included": true
}
}
}
}
Get JSON output - quality_checker
获取JSON输出 - quality_checker
python plugins/sanctum/skills/test-updates/scripts/quality_checker.py
--validate tests/test_my_module.py --output-json
--validate tests/test_my_module.py --output-json
python plugins/sanctum/skills/test-updates/scripts/quality_checker.py
--validate tests/test_my_module.py --output-json
--validate tests/test_my_module.py --output-json
Returns:
返回结果:
{
{
"success": true,
"success": true,
"data": {
"data": {
"static_analysis": {...},
"static_analysis": {...},
"dynamic_validation": {...},
"dynamic_validation": {...},
"metrics": {...},
"metrics": {...},
"quality_score": 85,
"quality_score": 85,
"quality_level": "QualityLevel.GOOD",
"quality_level": "QualityLevel.GOOD",
"recommendations": [...]
"recommendations": [...]
}
}
}
}
**Verification:** Run `pytest -v` to verify tests pass.**验证方式:** 执行`pytest -v`确认测试通过。When To Use It
适用场景
Use this skill when you need to:
- Update tests after code changes
- Generate tests for new features
- Improve existing test quality
- validate detailed test coverage
Perfect for:
- Pre-commit test validation
- CI/CD pipeline integration
- Refactoring with test safety
- Onboarding new developers
在以下场景中使用该技能:
- 代码变更后更新测试
- 为新功能生成测试
- 提升现有测试质量
- 验证测试的全面覆盖
尤其适合:
- 提交前的测试验证
- CI/CD流水线集成
- 借助测试安全地重构代码
- 新开发者入职培训
When NOT To Use
不适用场景
- Auditing test suites - use pensive:test-review
- Writing production code
- focus on implementation first
- Auditing test suites - use pensive:test-review
- Writing production code
- focus on implementation first
- 审计测试套件——请使用pensive:test-review
- 编写生产代码——请先专注于实现
- 审计测试套件——请使用pensive:test-review
- 编写生产代码——请先专注于实现
Workflow Integration
工作流集成
Phase 1: Discovery
阶段1:发现
- Scan codebase for test gaps
- Analyze recent changes
- Identify broken or outdated tests
See for detection patterns.
modules/test-discovery.md- 扫描代码库寻找测试缺口
- 分析近期代码变更
- 识别失效或过时的测试
详见中的检测模式。
modules/test-discovery.mdPhase 2: Strategy
阶段2:策略
- Choose appropriate BDD style (see )
modules/bdd-patterns.md - Plan test structure
- Define quality criteria
- 选择合适的BDD风格(详见)
modules/bdd-patterns.md - 规划测试结构
- 定义质量标准
Phase 3: Implementation
阶段3:实现
- Write failing tests (RED) - see
modules/tdd-workflow.md - Implement minimal passing code (GREEN)
- Refactor for clarity (REFACTOR)
See for generation templates.
modules/test-generation.md- 编写失败的测试(红阶段)——详见
modules/tdd-workflow.md - 实现最小化的可通过代码(绿阶段)
- 重构代码以提升可读性(重构阶段)
详见中的生成模板。
modules/test-generation.mdPhase 4: Validation
阶段4:验证
- Static analysis and linting
- Dynamic test execution
- Coverage and quality metrics
See for validation criteria.
modules/quality-validation.md- 静态分析与代码检查
- 动态测试执行
- 覆盖度与质量指标
详见中的验证标准。
modules/quality-validation.mdQuality Assurance
质量保障
The skill applies multiple quality checks:
- Static: Linting, type checking, pattern validation
- Dynamic: Test execution in sandboxed environments
- Metrics: Coverage, mutation score, complexity analysis
- Review: Structured checklists for peer validation
该技能会应用多维度的质量检查:
- 静态检查:代码检查、类型检查、模式验证
- 动态检查:在沙箱环境中执行测试
- 指标分析:覆盖度、变异测试分数、复杂度分析
- 同行评审:结构化的清单供同行验证
Examples
示例
BDD-Style Test Generation
BDD风格测试生成
See for additional patterns.
modules/bdd-patterns.mdpython
class TestGitWorkflow:
"""BDD-style tests for Git workflow operations."""
def test_commit_workflow_with_staged_changes(self):
"""
GIVEN a Git repository with staged changes
WHEN the user runs the commit workflow
THEN it should create a commit with proper message format
AND all tests should pass
"""
# Test implementation following TDD principles
passVerification: Run to verify tests pass.
pytest -v更多模式详见。
modules/bdd-patterns.mdpython
class TestGitWorkflow:
"""针对Git工作流操作的BDD风格测试。"""
def test_commit_workflow_with_staged_changes(self):
"""
GIVEN 一个包含已暂存变更的Git仓库
WHEN 用户运行提交工作流
THEN 应创建一个符合规范格式的提交
AND 所有测试均应通过
"""
# 遵循TDD原则的测试实现
pass验证方式: 执行确认测试通过。
pytest -vTest Enhancement
测试优化
- Add edge cases and error scenarios
- Include performance benchmarks
- Add mutation testing for robustness
See for enhancement strategies.
modules/test-enhancement.md- 添加边缘场景和错误场景
- 包含性能基准测试
- 增加变异测试以提升鲁棒性
优化策略详见。
modules/test-enhancement.mdIntegration with Existing Skills
与现有技能集成
- git-workspace-review: Get context of changes
- file-analysis: Understand code structure
- test-driven-development: Apply strict TDD discipline
- skills-eval: Validate quality and compliance
- git-workspace-review:获取代码变更上下文
- file-analysis:理解代码结构
- test-driven-development:严格遵循TDD规范
- skills-eval:验证质量与合规性
Success Metrics
成功指标
- Test coverage > 85%
- All tests follow BDD patterns
- Zero broken tests in CI
- Mutation score > 80%
- 测试覆盖度 > 85%
- 所有测试均遵循BDD模式
- CI流水线中无失效测试
- 变异测试分数 > 80%
Troubleshooting FAQ
故障排查FAQ
Common Issues
常见问题
Q: Tests are failing after generation
A: This is expected! The skill follows TDD principles - generated tests are designed to fail first. Follow the RED-GREEN-REFACTOR cycle:
- Run the test and confirm it fails for the right reason
- Implement minimal code to make it pass
- Refactor for clarity
Q: Quality score is low despite having tests
A: Check for these common issues:
- Missing BDD patterns (Given/When/Then)
- Vague assertions like
assert result is not None - Tests without documentation
- Long, complex tests (>50 lines)
Q: Generated tests don't match my code structure
A: The scripts analyze AST patterns and may need guidance:
- Use flag to match your preferred BDD style
--style - Check that source files have proper function/class definitions
- Review the generated scaffolding and customize as needed
Q: Mutation testing takes too long
A: Mutation testing is resource-intensive:
- Use flag for subset testing
--quick-mutation - Focus on critical modules first
- Run overnight for detailed analysis
Q: Can't find tests for my file
A: The analyzer uses naming conventions:
- Source: → Test:
my_module.pytest_my_module.py - Check that test files follow pytest naming patterns
- validate test directory structure is standard
问:生成测试后测试失败
答:这是正常现象!该技能遵循TDD原则——生成的测试设计为首先失败。请遵循RED-GREEN-REFACTOR周期:
- 运行测试并确认它因正确的原因失败
- 实现最小化代码使测试通过
- 重构代码以提升可读性
问:已有测试但质量分数较低
答:请检查以下常见问题:
- 缺少BDD模式(Given/When/Then)
- 模糊的断言,如
assert result is not None - 测试无文档说明
- 冗长复杂的测试(超过50行)
问:生成的测试与我的代码结构不匹配
答:脚本会分析AST模式,可能需要一些引导:
- 使用参数匹配你偏好的BDD风格
--style - 确保源文件有正确的函数/类定义
- 查看生成的脚手架并按需自定义
问:变异测试耗时过长
答:变异测试资源消耗较大:
- 使用参数进行子集测试
--quick-mutation - 先聚焦于核心模块
- 运行整夜以进行精细化分析
问:找不到对应文件的测试
答:分析器使用命名约定:
- 源文件:→ 测试文件:
my_module.pytest_my_module.py - 确保测试文件遵循pytest命名模式
- 确认测试目录结构符合标准
Performance Tips
性能优化技巧
- Large codebases: Use to focus on specific directories
--target - CI integration: Run validation in parallel with other checks
- Memory usage: Process files in batches for very large projects
- 大型代码库:使用参数聚焦于特定目录
--target - CI集成:与其他检查并行运行验证
- 内存使用:处理超大型项目时分批处理文件
Getting Help
获取帮助
- Check script outputs for detailed error messages
- Use flag for more information
--verbose - Review the validation report for specific recommendations
- Start with small modules to understand patterns before scaling
- 查看脚本输出获取详细错误信息
- 使用参数获取更多信息
--verbose - 查看验证报告获取具体建议
- 先从小模块入手理解模式,再进行规模化使用