claude-code/claude-zh/rules/common/testing.md

990 B
Raw Permalink Blame History

測試要求 (Testing Requirements)

最低測試覆蓋率80%

測試類型(皆為必需):

  1. 單元測試 (Unit Tests) - 個別函式、工具、元件。
  2. 整合測試 (Integration Tests) - API 子端點、資料庫操作。
  3. 端對端測試 (E2E Tests) - 關鍵使用者流程(每個語言選定適合的框架)。

測試驅動開發 (Test-Driven Development)

強制性 工作流:

  1. 先撰寫測試 (紅燈 RED)。
  2. 執行測試 — 應該會 失敗
  3. 撰寫最少量的實作程式碼 (綠燈 GREEN)。
  4. 執行測試 — 應該會 通過
  5. 重構 (優化 IMPROVE)。
  6. 驗證覆蓋率 (80% 以上)。

測試失敗疑難排解

  1. 使用 tdd-guide agent。
  2. 檢查測試隔離性。
  3. 驗證 Mock 是否正確。
  4. 修復實作,而非修改測試(除非測試本身有誤)。

Agent 支援

  • tdd-guide — 針對新功能開發,應 主動 使用,強制執行「測試先行」原則。