golang-testing

Write and review production-grade Go tests using table-driven patterns, testify, fuzzing, and goleak.

Updated May 9, 2026
One-click install
npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-testing-luminavault
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/LuminaVault/LuminaVaultShared/tree/main/.agents/skills/golang-testing
Command: npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-testing-luminavault

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go test suites often suffer from flaky tests, goroutine leaks, missing edge cases, and tests coupled to implementation details. This Skill provides opinionated, idiomatic guidance for writing, reviewing, auditing, and debugging Go tests so they act as executable specifications rather than brittle coverage padding. ## Core Features & Use Cases - Table-Driven & Parallel Tests: Enforces named subtests, t.Parallel() for independent cases, and black-box testing via external test packages. - Concurrency & Time Safety: Detects goroutine leaks with goleak, uses testing/synctest and fake clocks (clockwork) for deterministic time-dependent tests, and mandates -race in CI. - Integration & HTTP Testing: Separates integration tests with //go:build integration tags, uses testify/suite for setup/teardown, and tests handlers with httptest.NewRecorder instead of real servers. - Use Case: When asked to test a worker pool, the Skill produces tests that verify task completion AND use goleak.VerifyTestMain to prove Stop() leaks no goroutines. ## Quick Start Ask the agent to write comprehensive table-driven tests with goroutine leak detection for your Go package.

Frequently Asked Questions about golang-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write table-driven tests in Go?▼

Define a slice of anonymous structs with a name field plus inputs and expected outputs, then loop with t.Run(tt.name, ...) for each case. Named subtests make failures identifiable and allow running individual cases with go test -run TestName/subtest.

How to detect goroutine leaks in Go tests?▼

Use go.uber.org/goleak by calling goleak.VerifyTestMain(m) in TestMain for package-level detection, or defer goleak.VerifyNone(t) inside individual tests. This fails the test if any goroutines are still running after completion.

Should I use testing.Short() or build tags for integration tests?▼

Use the //go:build integration build tag, not testing.Short(). Short-mode tests still compile into the binary and only skip when the -short flag is passed, while build-tagged files are fully excluded from compilation. Run them with go test -tags=integration ./...

How do I test time-dependent Go code without slow sleeps?▼

Refactor the code to accept a clock interface instead of calling time.Now() directly, then inject clockwork.NewFakeClock() in tests and advance time instantly. On Go 1.25+, testing/synctest also provides deterministic synthetic time for goroutines and timers.

testify vs standard library for Go test assertions?▼

Use testify (assert, require, mock, suite) as a helper layer on top of the standard testing package, not a replacement. Mock interfaces rather than concrete types, and use testify/suite with SetupSuite and TearDownTest for organized integration tests.

Why do my Go test failures point to the wrong line?▼

Your test helper is missing t.Helper() as its first statement. Without it, failures report the line inside the helper function; with it, the testing framework reports the caller's file and line where the helper was invoked.