tdd-enforcer
強制測試驅動開發工作流程
在程式碼之後撰寫測試會導致測試覆蓋率的缺口和不穩定的測試。此技能引導 TDD 循環分為明確的階段:紅色(撰寫失敗測試)、綠色(最小實作)和重構(在測試保持綠色的同時改善程式碼)。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“tdd-enforcer”。 Use TDD to implement user registration with email validation
预期结果:
- Creating tests first with AAA pattern
- Test: should reject invalid email formats (Red)
- Test: should create user with hashed password (Red)
- Test: should return 400 for missing fields (Red)
- Writing minimal implementation to pass tests (Green)
- Refactoring for clarity while tests stay green
正在使用“tdd-enforcer”。 Write tests for authentication login flow
预期结果:
- Test: should return user and token for valid credentials (Red)
- Test: should throw error for wrong password (Red)
- Test: should hash password before saving (Red)
- Minimal implementation passing all tests (Green)
- Refactoring mock setup for reusability
安全审计
安全All 83 static findings are FALSE POSITIVES. This is a pure documentation skill containing only TypeScript code examples demonstrating TDD patterns. The scanner misinterpreted markdown code fences as shell backticks, bcrypt password hashing as weak crypto, Jest testing functions as system reconnaissance, and standard relative imports as path traversal. No executable code or malicious patterns exist.
风险因素
🌐 网络访问 (3)
⚙️ 外部命令 (34)
📁 文件系统访问 (1)
质量评分
你能构建什么
建立測試覆蓋率
實作新功能的開發人員使用 TDD 在撰寫實作程式碼之前建立全面的測試套件。
驗證測試品質
審核者驗證提取請求遵循 TDD 原則,具有正確結構的 AAA 測試和足夠的覆蓋率。
學習 TDD 實踐
剛接觸測試驅動開發的團隊遵循結構化工作流程來建立測試習慣並撰寫可維護的測試。
试试这些提示
Use TDD workflow for this feature. First write failing tests that describe the expected behavior. Tests must use AAA pattern (Arrange, Act, Assert). Verify tests fail before writing implementation.
Write unit tests for this service following TDD. Create tests using describe blocks organized by method. Include tests for edge cases, error conditions, and success paths. Use AAA pattern and descriptive test names.
Review the test coverage requirements. Ensure business logic (src/services/) has 90%+ coverage, utilities have 90%+ coverage, and overall coverage is 75%+. Flag any code paths without test coverage.
With all tests passing, refactor the code for quality. Remove duplication, improve naming, and enhance readability. Do not change behavior. All tests must remain green throughout refactoring.
最佳实践
- 總是在實作之前撰寫失敗的測試,以確認測試確實能捕捉到缺少的功能
- 一致地使用 AAA 模式:每個測試中都包含 Arrange(設定)、Act(執行)、Assert(驗證)
- 專注於行為而非實作細節,以使重構更加容易
避免
- 在測試之前撰寫實作程式碼(違背了 TDD 的目的)
- 測試實作細節而非可觀察的行為
- 建立涵蓋過多場景的巨型測試
常见问题
此技能支援哪些工具?
它強制執行什麼覆蓋率閾值?
我可以在既有程式碼上使用嗎?
我的資料安全嗎?
為什麼測試需要先失敗?
這與一般的測試建議有何不同?
开发者详情
许可证
MIT
仓库
https://github.com/Barnhardt-Enterprises-Inc/quetrex-plugin/tree/main/templates/skills/tdd-enforcer引用
main
文件结构
📄 SKILL.md