golang-testing

Guide Go testing with table-driven tests, mocks, and integration tests.

4|Updated Dec 23, 2025
One-click install
npx skills add https://github.com/89jobrien/steve --skill golang-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/89jobrien/steve/tree/main/steve/skills/golang-testing
Command: npx skills add https://github.com/89jobrien/steve --skill golang-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides structured guidance for comprehensive Go testing including table-driven tests, mocking, and integration tests.

Core Features & Use Cases

  • Table-Driven Tests: Standard patterns for multiple cases.
  • Mocking & Interfaces: Design and implement test doubles.
  • Benchmarks & Integration Tests: Performance checks and externalized testing.

Quick Start

Create tests in a Go module and run go test with benchmarks.

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 use a slice of test cases with inputs and expected outputs, iterating through each case in a single test function. This pattern reduces code duplication and makes it easy to add new test scenarios without writing separate test functions.

What's the best way to mock dependencies in Go tests?

Interface-based mocking is the standard Go approach: define interfaces for dependencies, create test doubles implementing those interfaces, and inject them during testing. This avoids external coupling and enables comprehensive unit testing without external services.

Can I run integration tests with external services in Go?

Yes, testcontainers enable integration testing by spinning up containerized versions of databases, message queues, and APIs. Your tests interact with real service instances in isolated containers, then tear them down automatically after tests complete.

How do I benchmark Go code performance?

Go's built-in benchmarking uses functions named BenchmarkX in test files and runs with `go test -bench`. Benchmarks measure execution time and memory allocation, helping identify performance bottlenecks and track optimization progress across releases.

What testing tools and libraries work well with Go?

Testify provides assertions and mocking helpers that simplify test code. Testcontainers handles integration test infrastructure. The standard library's testing package covers unit tests and benchmarks. Together they cover unit, integration, and performance testing needs.

How should I organize test files in a Go project?

Place test files alongside source code with a `_test.go` suffix in the same package. Group related tests logically, use table-driven patterns for similar cases, and keep test setup in helper functions. This structure keeps tests maintainable and discoverable with `go test`.