golang-testing

Automate Go testing guidance with structured patterns for unit tests, benchmarks, and fuzzing.

1|Updated Mar 20, 2024
One-click install
npx skills add https://github.com/flag3/dotfiles --skill golang-testing-flag3
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/flag3/dotfiles/tree/main/.claude/skills/golang-testing
Command: npx skills add https://github.com/flag3/dotfiles --skill golang-testing-flag3

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often struggle to maintain reliable tests as codebases grow. This Skill provides proven testing patterns—such as table-driven tests, subtests, benchmarks, fuzzing, and coverage workflows—to help you write robust, maintainable tests following a TDD approach.

Core Features & Use Cases

  • Table-driven tests to cover multiple scenarios with concise code.
  • Subtests and parallel tests to speed up feedback and organize test suites.
  • Benchmarks and fuzz tests to ensure performance and resilience.
  • Integrated guidance on building a practical TDD workflow in Go projects.

Quick Start

Create a new Go module, add a simple function and a test using a table-driven approach, then run go test ./... to see tests pass.

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?

Table-driven tests in Go organize multiple test cases into a slice of structs, each containing inputs and expected outputs. Define a test table, loop through cases, and run assertions for each. This pattern reduces code duplication and scales test coverage efficiently across scenarios.

What's the best way to structure Go unit tests for TDD?

Test-driven development in Go starts by writing tests before implementation, using the standard testing package and organizing tests with descriptive names. Use subtests to group related cases, table-driven patterns for multiple scenarios, and run tests with `go test` to validate code as you build.

How do I use subtests and parallel tests to speed up Go test execution?

Subtests organize related test cases hierarchically using `t.Run()`, improving readability and failure isolation. Mark subtests with `t.Parallel()` to run concurrently, reducing total execution time. This approach maintains clean output while accelerating feedback cycles in larger test suites.

How do I benchmark and fuzz test Go code?

Benchmarks measure function performance using the `testing.B` type and `go test -bench` flag, revealing execution time and allocations. Fuzz testing uses `testing.F` to generate random inputs and expose edge cases. Both ensure code remains performant and resilient as projects grow.

Can I integrate test coverage workflows into a Go project?

Yes. Go's built-in coverage tools generate reports with `go test -cover` to measure code coverage percentage, or `go test -coverprofile` to create detailed profiles. Combine with subtests and table-driven patterns to identify untested paths and maintain reliability across your codebase.

What code organization and tooling do I need for reliable Go testing?

Reliable Go testing requires organizing tests alongside source files with `_test.go` naming, using consistent import paths, and leveraging `go test ./...` to run the full suite. Follow TDD patterns with table-driven and parallel tests to ensure maintainable, fast feedback as codebases scale.