golang-testing

Implements Go testing patterns including table-driven tests, benchmarks, fuzzing, and coverage.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill golang-testing-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/golang-testing
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill golang-testing-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing idiomatic, maintainable Go tests requires knowing many patterns—table-driven tests, subtests, mocks, benchmarks, and fuzzing. This Skill provides a complete reference so you write correct tests following TDD without searching documentation. ## Core Features & Use Cases - TDD Workflow Guidance: Step-by-step RED-GREEN-REFACTOR cycle with concrete Go code examples. - Comprehensive Test Patterns: Table-driven tests, subtests, parallel tests, test helpers, golden files, interface-based mocking, and HTTP handler testing. - Performance & Robustness Testing: Benchmarks with memory allocation tracking, fuzz tests (Go 1.18+), and coverage measurement with CI integration. - Use Case: When adding a new Go function, activate this Skill to generate a table-driven test with error cases, run it with race detection, and verify coverage meets your target. ## Quick Start Write table-driven tests with benchmarks and coverage for my Go package using the golang-testing skill.

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 structs with name, inputs, and expected outputs, then loop over cases calling t.Run for each subtest. This pattern covers many scenarios including error cases with minimal code and is the idiomatic Go testing standard.

How to run benchmarks and measure memory allocations in Go?▼

Write functions starting with Benchmark that loop b.N times, then run go test -bench=. -benchmem. Use b.ResetTimer after setup and b.Run for sub-benchmarks comparing different input sizes or implementations.

Does Go support fuzz testing natively?▼

Yes, Go 1.18+ includes built-in fuzzing via testing.F. Add seed corpus inputs with f.Add, define property assertions in f.Fuzz, and run with go test -fuzz=FuzzName -fuzztime=30s.

How do I mock dependencies in Go tests?▼

Define interfaces for dependencies, then create mock structs with function fields matching the interface methods. Inject the mock into your service under test to control behavior per test case without external libraries.

Why are my Go tests flaky and how do I detect it?▼

Flakiness often comes from time.Sleep calls, shared state, or missing tt := tt capture in parallel subtests. Detect flaky tests by running go test -count=10 and use channels or conditions instead of sleeps.

How do I measure Go test coverage in CI?▼

Run go test -race -coverprofile=coverage.out ./... then use go tool cover -func to check totals. You can fail the CI build when coverage drops below a threshold like 80 percent using a shell check.