golang-testing

A guide to testing Go programs, including table-driven tests, subtests, benchmarks, fuzzing, coverage, and TDD. TDD means writing a failing test first, making it pass, then improving the code.

In plain words
What is it for?
Use it to add tests, improve coverage, measure performance, test input validation with fuzzing, or follow a TDD workflow in a Go project.
Why use it?
It provides repeatable ways to check behavior, performance, and unusual inputs while developing Go code.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/codelably/harmony-claude-code/golang-testing
Any agent
npx skills add codelably/harmony-claude-code --skill golang-testing
Clone the repo
git clone --depth 1 https://github.com/codelably/harmony-claude-code

Made for: Claude Code, Codex.

Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,735 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00035 $0.04735
Opus 5 $0.00017 $0.02367
Sonnet 5 $0.00007 $0.00947
Haiku 4.5 $0.00003 $0.00473

Measured 2d ago against content hash e01c20058083, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

golang-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/zh-TW/skills/golang-testing/SKILL.md · 711 lines

How it starts

The opening of the file, as written. The whole thing — 711 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Go 測試模式

用於撰寫可靠、可維護測試的完整 Go 測試模式,遵循 TDD 方法論。

何時啟用

  • 撰寫新的 Go 函式或方法
  • 為現有程式碼增加測試覆蓋率
  • 為效能關鍵程式碼建立基準測試
  • 實作輸入驗證的模糊測試
  • 在 Go 專案中遵循 TDD 工作流程

Go 的 TDD 工作流程

RED-GREEN-REFACTOR 循環

RED     → 先寫失敗的測試
GREEN   → 撰寫最少程式碼使測試通過
REFACTOR → 在保持測試綠色的同時改善程式碼
REPEAT  → 繼續下一個需求

Go 中的逐步 TDD

// 步驟 1:定義介面/簽章
// calculator.go
package calculator

func Add(a, b int) int {
    panic("not implemented") // 佔位符
}

// 步驟 2:撰寫失敗測試(RED)
// calculator_test.go
package calculator

import "testing"

func TestAdd(t *testing.T) {
    got := Add(2, 3)
    want := 5
    if got != want {
        t.Errorf("Add(2, 3) = %d; want %d", got, want)
    }
}

// 步驟 3:執行測試 - 驗證失敗
// $ go test
// --- FAIL: TestAdd (0.00s)
// panic: not implemented

// 步驟 4:實作最少程式碼(GREEN)
func Add(a, b int) int {
    return a + b
}

// 步驟 5:執行測試 - 驗證通過
// $ go test
// PASS

// 步驟 6:如需要則重構,驗證測試仍然通過

表格驅動測試

Go 測試的標準模式。以最少程式碼達到完整覆蓋。

func TestAdd(t *testing.T) {
    tests := []struct {
        name     string
        a, b     int
        expected int
    }{
        {"positive numbers", 2, 3, 5},
        {"negative numbers", -1, -2, -3},
        {"zero values", 0, 0, 0},
        {"mixed signs", -1, 1, 0},
        {"large numbers", 1000000, 2000000, 3000000},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got := Add(tt.a, tt.b)
            if got != tt.expected {
                t.Errorf("Add(%d, %d) = %d; want %d",
                    tt.a, tt.b, got, tt.expected)
            }
        })
    }
}

帶錯誤案例的表格驅動測試

func TestParseConfig(t *testing.T) {
    tests := []struct {
        name    string
        input   string
        want    *Config
        wantErr bool
    }{
        {
            name:  "valid config",
            input: `{"host": "localhost", "port": 8080}`,
            want:  &Config{Host: "localhost", Port: 8080},
        },
        {
            name:    "invalid JSON",
            input:   `{invalid}`,
            wantErr: true,
        },
        {
            name:    "empty input",
            input:   "",
            wantErr: true,
        },
        {
            name:  "minimal config",
            input: `{}`,
            want:  &Config{}, // 零值 config
        },
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := ParseConfig(tt.input)

            if tt.wantErr {
                if err == nil {
                    t.Error("expected error, got nil")
                }
                return
            }

            if err != nil {
                t.Fatalf("unexpected error: %v", err)
            }

            if !reflect.DeepEqual(got, tt.want) {
                t.Errorf("got %+v; want %+v", got, tt.want)
            }
        })
    }
}

Read the full file on GitHub · 711 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 711 lines · 35 tokens per session scan A e01c20058083

Subscribe to this mod's changes

golang-testing is a skill published in the GitHub repository codelably/harmony-claude-code (42 stars, last pushed 6mo ago), licensed MIT. It adds 35 tokens to every session and 4,735 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

go-rig

Use this skill when building, reviewing, or refactoring Go code that must follow strict design discipline — ATDD/TDD workflow, explicit dependency injection, package-boundary discipline, and structured code review. Complements CLAUDE.md by focusing on process and design judgment rather than version-specific Go…

mudrii/openclaw-dashboard · 64 tokens

golang-testing

Go testing patterns including table-driven tests, subtests, benchmarks, fuzzing, and test coverage. Follows TDD methodology with idiomatic Go practices.

jmrplens/libgen-mcp · 35 tokens

go-tdd-baby-steps

TDD with baby steps for Go. Use when writing tests, doing TDD, practicing red-green-refactor, or when test cycles feel too large and risky. Also use when the user asks about incremental test development, test-first workflow, or wants help breaking a feature into small testable steps. Covers table-driven tests…

gonzaloserrano/gopilot · 92 tokens

blitz

/blitz - Blitz Mode Commander.

samibs/skillfoundry · 9 tokens

dev-workflow

How to build the myscrape-go codebase. Use whenever implementing, fixing, refactoring, or extending Go code in this repo — covers the stable-tools rule, the TDD loop, the pre-commit gate, and commit discipline.

Bonifatius94/myscrape · 53 tokens

go-rig

Use this skill when building, reviewing, or refactoring Go code that must follow strict design discipline — ATDD/TDD workflow, explicit dependency injection, package-boundary discipline, and structured code review. Complements CLAUDE.md by focusing on process and design judgment rather than version-specific Go…

mudrii/golink · 64 tokens