技能 tdd-workflows-tdd-red
🧪

tdd-workflows-tdd-red

安全

為 TDD 紅階段生成失敗的測試

沒有明確的測試定義就開始 TDD 會導致涵蓋率不完整。此技能在實作開始前建立全面的失敗測試,定義預期的行為。

支援: Claude Codex Code(CC)
📊 71 充足
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「tdd-workflows-tdd-red」。 使用 Jest 為密碼驗證函數生成失敗的測試

預期結果:

完整的測試檔案,包含 describe 區塊、mock 設定和測試案例,涵蓋最小長度、特殊字元要求和邊緣情況。每個測試都預期特定的驗證失敗,這些失敗將在實作完成後通過。

正在使用「tdd-workflows-tdd-red」。 使用 pytest 和 Hypothesis 為字串反轉函數建立屬性測試

預期結果:

參數化測試函數,驗證反轉後的字串再次反轉等於原始字串、維持字元數量,並正確處理 Unicode 字元。

安全審計

安全
v1 • 2/25/2026

All static analysis findings are false positives. The detected patterns are code examples in markdown documentation, not executable code. Lines 73-75 show JavaScript mock function syntax (jest.fn), lines 84-85 show Go t.Parallel() method calls, line 88 shows Ruby RSpec let blocks, and lines 134+ contain TypeScript test examples in markdown code blocks. No actual shell execution, cryptographic operations, or system reconnaissance code exists in this skill.

1
已掃描檔案
167
分析行數
0
發現項
1
審計總數
未發現安全問題
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
31
社群
100
安全
91
規範符合性

你能建構什麼

新功能 TDD 工作流程

在實作新的認證服務之前,生成全面的失敗測試,涵蓋有效憑證、無效輸入和邊緣情況。

API 合約測試

建立合約測試,在建立端點實作之前定義預期的 API 請求和回應格式。

舊程式碼測試涵蓋率

透過生成測試來記錄目前的行為,在重構之前為現有程式碼新增遺漏的測試涵蓋率。

試試這些提示

基本單元測試生成
Generate failing unit tests for a function that validates email addresses. Use pytest framework. Cover valid emails, invalid formats, empty strings, and null inputs.
服務層測試
Create failing tests for a UserService with methods: createUser, getUserById, deleteUser. Use Jest with mocked UserRepository. Include error handling for duplicate emails and missing users.
基於屬性的測試
Generate property-based tests for a sorting function using fast-check. Verify that output is always sorted, maintains original length, and preserves all input elements.
整合測試套件
Create failing integration tests for a payment processing workflow including: successful payment, declined card, insufficient funds, and network timeout scenarios. Use RSpec with shared examples.

最佳實務

  • 使用 should_X_when_Y 命名慣例來清楚記錄預期行為
  • 保持測試隔離,測試案例之間沒有依賴關係
  • 驗證測試因正確的原因(缺少行為)而失敗,而非設定錯誤

避免

  • 測試實作細節而非可觀察的行為
  • 建立無需實作功能就能立即通過的測試
  • 使用複雜的設定程式碼模糊測試意圖

常見問題

什麼是 TDD 紅階段?
紅階段是測試驅動開發的第一步,在撰寫任何實作程式碼之前,先撰寫失敗的測試來定義預期的行為。
我如何驗證測試因正確的原因而失敗?
個別執行每個測試,並檢查失敗訊息是否指示缺少功能或斷言失敗,而非語法錯誤、匯入問題或設定問題。
支援哪些測試框架?
此技能支援 JavaScript/TypeScript 的 Jest 和 Vitest、Python 的 pytest、Go 的內建測試套件,以及 Ruby 的 RSpec。
我應該 mock 外部依賴嗎?
是的,mock 所有外部依賴,包括資料庫、API 和檔案系統,以確保測試快速、可靠且真正隔離的單元測試。
我應該包含多少邊緣情況?
涵蓋空/空輸入、邊界值、特殊字元、錯誤條件,以及與您的使用案例相關的任何領域特定的邊緣情況。
生成失敗的測試後我该做什麼?
進入綠階段,實作使所有測試通過所需的最少程式碼,然後在保持測試通過的情況下重構。

開發者詳情

檔案結構

📄 SKILL.md