技能 tdd-enforcer
🧪

tdd-enforcer

安全 🌐 网络访问⚙️ 外部命令📁 文件系统访问

強制測試驅動開發工作流程

在程式碼之後撰寫測試會導致測試覆蓋率的缺口和不穩定的測試。此技能引導 TDD 循環分為明確的階段:紅色(撰寫失敗測試)、綠色(最小實作)和重構(在測試保持綠色的同時改善程式碼)。

支持: Claude Codex Code(CC)
📊 70 充足
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“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

安全审计

安全
v5 • 1/16/2026

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.

2
已扫描文件
654
分析行数
3
发现项
5
审计总数
审计者: claude 查看审计历史 →

质量评分

38
架构
100
可维护性
87
内容
21
社区
100
安全
91
规范符合性

你能构建什么

建立測試覆蓋率

實作新功能的開發人員使用 TDD 在撰寫實作程式碼之前建立全面的測試套件。

驗證測試品質

審核者驗證提取請求遵循 TDD 原則,具有正確結構的 AAA 測試和足夠的覆蓋率。

學習 TDD 實踐

剛接觸測試驅動開發的團隊遵循結構化工作流程來建立測試習慣並撰寫可維護的測試。

试试这些提示

開始 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 的目的)
  • 測試實作細節而非可觀察的行為
  • 建立涵蓋過多場景的巨型測試

常见问题

此技能支援哪些工具?
適用於 Claude、Codex 和 Claude Code。為任何測試框架提供指導。
它強制執行什麼覆蓋率閾值?
需要 75% 的整體覆蓋率。業務邏輯和工具程式需要 90% 以上的覆蓋率。
我可以在既有程式碼上使用嗎?
可以。對新功能套用 TDD。對於既有程式碼,在進行更改之前先撰寫測試。
我的資料安全嗎?
是的。此技能僅提供指導。它不存取檔案或執行程式碼。
為什麼測試需要先失敗?
失敗的測試確認測試實際上是在檢查該功能。如果測試在實作之前通過,那麼它們不是在測試正確的內容。
這與一般的測試建議有何不同?
這強制執行嚴格的 TDD 循環:紅色(失敗測試)、綠色(最小程式碼)、重構。許多指南跳過了先撰寫失敗測試的紀律。