Agent skill · software engineering · affaan-m
golang-testing
Go testing patterns including table-driven tests, subtests, benchmarks, fuzzing, and test coverage. Follows TDD methodology with idiomatic Go practices.
Why this skill is useful
Provides specific Go testing patterns and TDD methodologies that the AI wouldn't reliably generate on its own.
What it needs
About 7k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
Go 測試模式 用於撰寫可靠、可維護測試的完整 Go 測試模式,遵循 TDD 方法論。 何時啟用 撰寫新的 Go 函式或方法 為現有程式碼增加測試覆蓋率 為效能關鍵程式碼建立基準測試 實作輸入驗證的模糊測試 在 Go 專案中遵循 TDD 工作流程 Go 的 TDD 工作流程 RED-GREEN-REFACTOR 循環 Go 中的逐步 TDD 表格驅動測試 Go 測試的標準模式。以最少程式碼達到完整覆蓋。 帶錯誤案例的表格驅動測試 子測試 組織相關測試 並行子測試 測試輔助函式 輔助函式 臨時檔案和目錄 Golden 檔案 使用儲存在 testdata/ 中的預期輸出檔案進行測試。 使用介面 Mock 基於介面的 Mock 基準測試 基本基準測試 不同大小的基準測試 記憶體分配基準測試 模糊測試(Go 1.18+) 基本模糊測試 多輸入模糊測試 測試覆蓋率 執行覆蓋率 覆蓋率目標 程式碼類型 目標 ----------- ------ 關鍵業務邏輯 100% 公開 API 90%+ 一般程式碼 80%+ 產生的程式碼 排除 HTTP Handler 測試 測試指令 最佳實務 應該做的: 先寫測試(TDD) 使用表格驅動測試以獲得完整覆蓋 測試行為,而非實作 在輔助函式中使用 t.Helper() 對獨立測試使用 t.Parallel() 用 t.Cleanup() 清理資源 使用描述情境的有意義測試名稱 不應該做的: 不要直接測試私有函式(透過公開 API 測試) 不要在測試中使用 time.Sleep()(使用 channels 或條件) 不要忽略不穩定測試(修復或移除它們) 不要 mock 所有東西(可能時偏好整合測試) 不要跳過錯誤路徑測試 CI/CD 整合 記住:測試是文件。它們展示你的程式碼應該如何使用。清楚地撰寫並保持更新。
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/golang-testing--8ee507