mvrahden/go-test/writing-gotest-tests
Claude Code and agent skill by mvrahden/go-test
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Use when writing, fixing, reviewing, or restructuring tests in a Go repository that uses the gotest framework (github.com/mvrahden/go-test) — `*TestSuite` structs, `gotest.T`, `BeforeEach`/`AfterAll` hooks, `*Fixture` types, or the `gotest` CLI — when migrating testify or stdlib tests to gotest, and when setting up or fixing CI for a gotest repository.
Install
npx vskill@latest install mvrahden/go-test/writing-gotest-testsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as mvrahden/go-test/writing-gotest-tests.
Writing gotest tests
gotest inverts habits learned from stdlib/testify. Follow this file's rules; consult reference/ only when the task touches that area — except reference/setup.md, which every task follows before writing anything.
Start here: version and upgrade
The repo has the library; the CLI runs via Go's tool directive, so every command is go tool gotest <args> — never a global go install binary. Before writing anything, check the pin and what the module can take:
The first line prints the pin (and a newer release, if any); the second the module's go line; the third every release with its go line. Upgrade to the newest release whose go line is not newer than the module's, when it is newer than the pin — go get -tool github.com/mvrahden/go-test/cmd/gotest@<release> — never to @latest blindly: go get would silently raise the project's Go. Do not upgrade when the pin is (replaced) (a source build: assume current behavior), the module is vendored, instructions rule out dependency changes, the task only reads code, or the check fails. Then follow reference/setup.md (after-upgrade steps, keeping the pin, a module without go-test yet, go.work, vendoring). A FAIL: refusal about a drifted binary is never a fault in the tests: switch to go tool gotest; never upgrade just to silence it.
This skill describes v1.41, the newest release; a rule tagged with a later version waits for that release. On a release you could not upgrade from, read reference/versions.md before writing anything: it lists what each older release lacks or does differently, including rules below that fail there (on v1.25.x, rules 2, 3 and 10). A rule tagged v1.27+ (or later) needs that release; skip it on older ones.
The Two Runners — a complete run is BOTH commands
go test ignores gotest suites (signature incompatibility, by design). gotest runs suites and never runs stdlib tests — it prints a stderr note: N stdlib test(s) … not run when it skips them (and [no suites] for a package holding nothing else). Running only one command silently misses tests. Always finish with:
Add -race to both before calling anything done.
Under an agent (AI_AGENT, or CLAUDECODE=1) a text run prints for you (v1.42+): only what failed, then one closing line, last on stdout, that survives tail -1: gotest: PASS|FAIL|EMPTY exit <code> | tests: … | packages: … | rerun: <command>. Read the verdict and exit code from that line, never from the absence of FAIL; a suite that ran none of its tests fails the run with exit 2. go tool gotest --failed reruns only what the last run in this directory failed, with -json, spec and summary too, and exits 2 when nothing is recorded to rerun, 1 when a recorded failure names a test that is gone. --agent=false or GOTEST_AGENT=0 gives you go test's text instead. While you iterate, go tool gotest --changed ./... (v1.42+) runs only the packages whose sources changed since the last run here, or that failed in it; its closing line says how many it left out, so the final check still runs everything.
Before you report a change done, audit it against its base (v1.42+): go tool gotest audit --base=$(git merge-base origin/main HEAD) reads both trees' suites from source and lists every weakening before the behaviors added, removed, reworded, moved and changed: a test removed, an X_ or F_ added, a guard, a raised budget or NoDeadline, a new suppression, a rewritten snapshot, fewer assertions, a new AssertsBy. Each one is what the change meant, said in your report, or a mistake to undo. Add --run to run what changed: each behavior then shows its verdict, and the changed production lines no test executed are listed. When the change adds logic, add --mutate (v1.42+) within its budget: it makes each changed line a test executed wrong and reports the lines no test noticed. For a survivor, write the assertion that tells the mutant apart; only a mutant no test can tell apart, such as a heuristic's equally valid result, takes //gotest:mutate-ignore <the true reason>, which audit lists as a suppression. The gotest plugin's stop hook runs the same audit when you end a turn and hands you each new weakening once: undo it, or name it in your final message.
When the repository keeps OpenSpec scenarios (specs/ or openspec/specs/), bind each one you implement by its text (v1.42+): a t.When whose label is the scenario's WHEN and, directly under it, a t.It per THEN and AND, copied word for word. go tool gotest scenarios --verify then names every scenario no suite states, every clause two tests claim, and the verdict of each bound one; rewording a scenario means rewording its labels too.
The write loop
Write → lint → both runners → fix:
lint -fix applies every suggested fix, formats the files it rewrites and removes the imports its fixes left unused, so no gofmt or goimports pass is needed after it. Findings without a fix (t.T().Helper(), a t.T().Log, a stdlib test, …) need your edit: from v1.33 -fix lists them and exits 3; below, it exits 0 and prints nothing, so only the plain lint run shows them. Move on when plain lint exits 0.
The linter catches direct misuse (t.T() escapes even inside closures, outer-t in poll callbacks, testify idioms, focus leftovers, and fail-guard: any if cond { gotest.Fail(t, …) } or if err != nil { t.Fatal(err) } guard — assertions halt on failure, so state them directly: gotest.NoError(t, err), never a guarded fail). A test asserts, or says how it checks (v1.42+): a leaf that passes having made no assertion is vacuous, and --ci fails the run on it. Add the missing assertion; only a test that truly checks by other means (code given t.T(), a call that must not panic) declares it with t.AssertsBy("<how>"). Fixes can compose — a rewritten guard may itself be simplifiable; from v1.33 one -fix applies those too, below it re-run the pair until plain lint is clean. When two findings share a construct the linter reports only the stronger one (integrity over style); fix what it says before expecting style suggestions there.
Suppression follows rule tiers: integrity rules (poll-scope, suite-lifecycle, focus, …) can never be skipped project-wide; style and migration rules can, via .gotest.yml lint.skip or -skip-<rule> flags. Any rule yields to a //nolint:<rule> // <reason> comment on the finding's line or on a line of its own directly above it — and to one trailing the package line itself (package shop_test //nolint:stdlib-test // <reason>), which covers the whole FILE (not the package), whatever the tier; on the line above package it suppresses nothing. Write the reason (v1.42+: nolint-reason reports a comment without one, and gotest lint -suppressions lists every comment with its reason for review). The stdlib-test rule flags every stdlib TestXxx(*testing.T) (not Benchmark, Fuzz or Example functions — those show only in the runner's note) — when a stdlib test is intentional (assertion-layer tests, benchmarks-adjacent code), mark it that way, or the lint run fails. The linter does NOT catch: plain defer cleanup, shared mutable state in parallel suites, or structural problems — those are your job, below.
Core rules
- Suites are structs, naming is the API.
type XxxTestSuite struct{},
exported, methods func (s *X) TestBehavior(t *gotest.T). No registration and no TestMain needed — the CLI generates the harness invisibly (never commit the gotest_psuite_test.go/ gotest_pxsuite_test.go files gotest generate writes; gotest clean ./... removes them). A TestMain of your own still runs; keep resource setup out of it — that is what fixtures and BeforeAll are for. F_/X_ prefixes focus/exclude. A suite declares at least one Test*, Benchmark* or Fuzz* method (an X_ one counts); a *TestSuite type with none is refused, so name helper types otherwise (v1.37+). A generic suite runs only through one type alias per concrete type (type ArticleIndexTestSuite = IndexContractTestSuite[Article]); without an alias it never runs, and the run refuses it (v1.38+). Case-named methods taking *gotest.T/B/F on a test-file type that is no suite are refused unless a test file calls them, and so is a method named just Test, Benchmark or Fuzz (v1.38+).
- Lifecycle hooks own resources. Setup in
BeforeEach(orBeforeAll
for expensive read-only state), teardown in AfterEach/AfterAll — per-test state on suite fields in a sequential suite, in the returned context in a parallel one (rule 4). NEVER t.T().Cleanup, and no defer releasing a resource in a test method. Such a defer lints clean and is still wrong: it sits outside the teardown order the harness guarantees, and the setup cannot be shared or hoisted. Start goroutines with gotest.Go(t, fn), never a bare go: a panic on a bare goroutine kills the process before any teardown runs. wait := gotest.Go(…); defer wait() is the one defer that belongs in a test, and only for work that finishes on its own — never wait in the test on a server or poller that AfterEach stops (it deadlocks). (v1.34+) A goroutine BeforeAll starts for AfterAll to stop goes on the hook's t or a T derived from it (When, It, Each, NewTWithDeadline; gotest.NewT(t) in a *testing.T hook), never on a subtest the hook starts with t.Run: its wait runs before AfterAll and deadlocks. Below v1.34 every such wait did. Every BeforeAll needs an AfterAll (lifecycle-pair, integrity tier). A suite's AfterAll runs even when its BeforeAll failed or panicked midway, so release only what was actually set up — nil-check each field.
- Do not imitate existing tests blindly. Observed failure: agents copy
a repo's existing SuiteConfig() verbatim, propagating anti-patterns. A SuiteConfig() marker states intent: omit it entirely for defaults. Every positive duration the marker returns — a preset's included — is a budget: a test that outlives it fails even when it ignores its context. A duration it leaves at zero gets the default and, like having no marker, only bounds the context; gotest.NoDeadline disables one. On v1.26–v1.29 a zero/omitted duration meant NO deadline instead — compose onto a preset there (reference/config.md).
- Ask "why is this suite NOT parallel?" Observed failure: agents never
parallelize unprompted, even when asked to improve tests. The recipe:
```go func (s *ShopTestSuite) SuiteConfig() gotest.SuiteConfig { return gotest.SuiteConfig{Parallel: true} }
type shopCtx struct{ inv *Inventory }
func (s ShopTestSuite) BeforeEach(t gotest.T) *shopCtx { return &shopCtx{inv: NewInventory()} } ```
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/writing-gotest-tests/SKILL.md
Popularity
- Repository stars
- 130
- Repository forks
- 1
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mvrahden/go-test/writing-gotest-tests)