Golang testing

From HoangNguyen0403/agent-skills-standard · View interactive version

Golang testing is an AI agent skill from the GitHub repository HoangNguyen0403/agent-skills-standard. Write unit tests with table-driven patterns and interface mocking in Go. Use when writing Go unit tests, table-driven tests, or using mock interfaces.

How to use this skill

Skill file

Golang Testing

**Priority: P0 (CRITICAL)**

Universal anti-slop rules (identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps, shallow

assertions, coverage): anti-slop-rules.md. Only Go deltas follow.

Core Rule Anchors

when inputs are equivalent or setup is repetitive. Distinct scenarios or diverging setup may stay separate functions. Ban

duplicate identical rows (GUARD-GO-03); every declared field must be asserted in t.Run (GUARD-GO-UNCHECKED-WANT).

calculations directly, or use testcontainers-go for PostgreSQL repository verification.

least one non-trivial payload field, slice length, status enum, or domain invariant on T. Bare assert.NoError +

assert.NotNil is banned.

mapping; ban 1:1 mock echoing. In pure domain/ tests prefer struct fixtures over mock controllers (GUARD-GO-01).

Implementation Workflow

  1. Failing test first — RED before production code.
  2. Table-driven for equivalent inputs — t.Run per case ([BE-TEST-01]); assert all want/wantErr fields

(GUARD-GO-UNCHECKED-WANT).

  1. Compound guard branches — for &&/|| market or feature-flag conditions, assert each clause independently flips.
  2. Zero volatile fields — clear timestamps, dynamic IDs, and generated tokens before assert.Equal.
  3. No swallowed errors (GUARD-GO-SWALLOWED-ERR) — never if err != nil { return }; fail via t.Fatalf or

require.NoError.

  1. Mock via interfaces — DI with small consumer-centric interfaces (1–3 methods) ([BE-TEST-04]).
  2. Parallel & cleanup — t.Parallel() for independent tests; t.Cleanup() to restore state and release resources.
  3. Coverage — diagnostic and project-configured; verify risk-weighted critical paths.

Tools & Naming

Anti-Patterns

gap. Ban duplicate rows (GUARD-GO-03) and unasserted fields (GUARD-GO-UNCHECKED-WANT).

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.