go-testing
Write unit and integration tests for Go services. Use when creating, editing, or updating tests, test helpers, mocks, fuzz tests, or benchmarks in Go projects.
от Integralist★ 31 звезда на GitHub
Установить go-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Write Go tests test-first, with each case proving one behaviour through the
package's public API. Read and follow
conventions-go too: it sets style and linter
rules for test code (testCases/tc, rr, noctx, scopeguard, comments,
testify/mock), and wins where the two overlap. Before writing or changing
tests, read TEST-CONTRACTS for assertion
contracts. For acceptance suites, also read and follow
conventions-acceptance-tests: it
owns scenario-to-code structure for Go/Godog and Make/Bash workflows.
Style. For unit tests, ask whether the user prefers table-driven (default)
or f-tests (helper f in named subtests).
A test written before its types exist fails to compile, which doesn't count as red. So:
- Stub the types and signatures, returning zero values or a sentinel such as
errors.New("unimplemented"). - Write the test against the stub and run
go test; it must compile and fail on its assertion. - Write the least code that passes, then tidy up and delete dead code.
What each test proves
- One behaviour per case. The case name states it; a case proving two things becomes two cases.
- Every error path. Each error the public API can return gets a case that
checks the failure, matching errors with
errors.Isorerrors.AsType. Match on a substring only for an unexported third-party error. - Real assertions. Assert state changes, header values, or payloads, never
only
assert.NoErrorwhen the call returns values. Assert the fields that matter rather than whole structs withreflect.DeepEqualorcmp.Diff, which fail on timestamps and generated IDs. - Nothing unused. Deleting any field or setup step must break the test. Split cases with different setup into separate tables.
- Distinct paths only. Each case covers its own branch or dimension, not
a trivial variation of another. Add to an existing table before writing a
new
Test*function. - Cancellation. A long-running, I/O-bound, or goroutine-spawning function
gets a test proving it stops promptly when
ctxis cancelled. - Public API. Test through exported names, preferably from
package foo_test. Reach each branch through the public call that triggers it; delete any branch no public path reaches. Extract logic tointernal/only when it is a module with its own interface and a second caller or adapter (see code-module-design), not just to make it testable. - No coverage loss. Refactoring tests must never lower package statement
coverage (
go test -cover).
Patterns
Testify mocks. When a test double embeds mock.Mock, call its methods
through the embedded field—for example, m.Mock.Called(...) rather than
m.Called(...). The explicit receiver makes the mock dependency visible.
Table-driven:
// TestNormalize proves Normalize upper-cases input and rejects empty
// strings with ErrEmptyInput.
func TestNormalize(t *testing.T) {
testCases := []struct {
// name states the behaviour this case proves.
name string
// input is passed to Normalize.
input string
// expected is the result on success.
expected string
// wantErr is the sentinel to match with errors.Is, or nil.
wantErr error
}{
{name: "upper-cases valid input", input: "hello", expected: "HELLO"},
{name: "rejects empty input", input: "", wantErr: ErrEmptyInput},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result, err := Normalize(tc.input)
if tc.wantErr != nil {
if !errors.Is(err, tc.wantErr) {
t.Fatalf("expected %v, got %v", tc.wantErr, err)
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result != tc.expected {
t.Errorf("expected %q, got %q", tc.expected, result)
}
})
}
}
When cases prove one invariant across operations with different signatures,
give each case an invoke func(*Repository) error closure rather than
reaching for generics.
F-test:
// TestShout proves Shout upper-cases its input.
func TestShout(t *testing.T) {
// f checks one input against its expected output.
f := func(t *testing.T, input, expected string) {
t.Helper()
if got := Shout(input); got != expected {
t.Fatalf("Shout(%q) = %q; want %q", input, got, expected)
}
}
t.Run("converts to uppercase", func(t *testing.T) { f(t, "hello", "HELLO") })
t.Run("handles empty string", func(t *testing.T) { f(t, "", "") })
}
Helpers and context. Call t.Helper() in every helper. Pass
t.Context() (Go 1.24+), not context.Background(), to code under test; it
cancels when the test ends. Don't block on a bare <-t.Context().Done() for
an async wait, or a stuck test hangs until the suite times out; bound it:
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
select {
case <-renewed:
case <-ctx.Do
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/ACCEPTANCE.md
- references/COVERAGE-PRUNING.md
- references/FUZZ-AND-BENCHMARKS.md
- references/INTEGRATION.md
- references/REGULAR-EXPRESSIONS.md
FAQ
Что делает скилл go-testing?
Write unit and integration tests for Go services. Use when creating, editing, or updating tests, test helpers, mocks, fuzz tests, or benchmarks in Go projects.
Как установить скилл go-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл go-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…