go-testing

Write, review, audit, and debug Go tests using table-driven patterns, mocks, fuzzing, and race detection.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-testing-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-testing
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/go/go-testing
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-testing-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go test suites often suffer from flaky tests, unclear failure messages, over-mocked internals, and coverage chasing without real behavior constraints. This Skill provides executable specifications for writing deterministic, fast, behavior-focused Go tests and for reviewing, auditing, and debugging existing suites. ## Core Features & Use Cases - Test authoring workflows: Step-by-step guidance for table-driven tests with named subtests, testify assert/require usage, interface-based mocking, parallel tests, fuzzing, benchmarks, and integration tests behind build tags. - Review and audit checklists: Structured steps to verify PR test coverage of new branches, detect flakiness patterns like sleeps and shared state, and find gaps or implementation coupling in existing suites. - Debugging methodology: A reproduce-minimize-trace-fix workflow for failing or flaky tests, including goleak goroutine leak detection, race detector usage, and deterministic time via synctest or clockwork. - Use Case: When a CI pipeline fails intermittently on a Go test, use this Skill to isolate the test with -run and -count=10, identify the timing dependency, and replace it with a deterministic clock. ## Quick Start Ask the assistant to write table-driven unit tests with testify mocks for a specific Go function in your project.

Frequently Asked Questions about go-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 and inputs/expected outputs, then loop with t.Run(tt.name, ...) for each case. Named subtests give clear failure messages and enable filtering with go test -run TestName/subtest.

How do I mock dependencies in Go tests with testify?

Define an interface where the dependency is consumed, create a mock struct embedding mock.Mock, and implement methods that call m.Called with return values from args. Set expectations with mock.On and verify them with AssertExpectations.

When should I use require vs assert in testify?

Use require for setup preconditions where a failure should abort the test immediately, and assert for behavior verification where the test should report and continue. This keeps failure output focused on the actual broken contract.

How do I run integration tests separately from unit tests in Go?

Add a //go:build integration tag at the top of integration test files so they are excluded from the default fast run. Execute them explicitly with go test -tags=integration ./... in CI or on demand.

Why is my Go test flaky and how do I fix it?

Flakiness usually comes from timing sleeps, port binds, shared mutable state, or goroutine leaks. Reproduce with go test -count=10, check ordering with -shuffle=on, run the race detector, and replace real time with clockwork or testing/synctest.

Does Go support fuzz testing natively?

Yes, Go 1.18+ includes native fuzzing via FuzzFoo functions in the testing package. Seed the corpus with f.Add, define invariants in f.Fuzz, and run with go test -fuzz=FuzzName to hunt edge cases in parsers and hot paths.