golang-testing

Implement Go testing patterns with TDD, table-driven tests, and benchmarks.

1|Updated Apr 6, 2026
One-click install
npx skills add https://github.com/zero3041/PREP --skill golang-testing-zero3041
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/zero3041/PREP/tree/main/.claude/skills/skills/golang-testing
Command: npx skills add https://github.com/zero3041/PREP --skill golang-testing-zero3041

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill unit addresses the need for comprehensive testing practices in Go, enabling developers to write robust, maintainable, and reliable code through Test-Driven Development (TDD) and best practices.

Core Features & Use Cases

  • TDD Methodology: Follows a RED-GREEN-REFACTOR cycle for development.
  • Table-Driven Tests: Enables comprehensive test coverage with minimal code.
  • Subtests and Sub-benchmarks: Organizes related tests and benchmarks for clarity and efficiency.
  • Test Helper Functions: Provides utility functions for setup, assertions, and cleanup.
  • Golden Files: Allows for testing against expected outputs.
  • Mocking: Utilizes interface-based mocking for dependency isolation.
  • Benchmarks: Performs basic and memory allocation benchmarks.
  • Fuzzing: Implements fuzz tests for input validation.
  • Test Coverage: Offers guidance on coverage targets and how to exclude generated code.
  • HTTP Handler Testing: Demonstrates testing of HTTP handlers.
  • Testing Commands: Lists common testing commands in Go.

Quick Start

To begin using this Skill unit, open the SKILL.md file and review the TDD workflow and testing patterns outlined within.

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 structs to define test cases, looping through them with subtests to achieve comprehensive coverage with minimal code. This approach keeps test suites maintainable and readable.

What is the RED-GREEN-REFACTOR cycle in Go TDD?

The RED-GREEN-REFACTOR cycle in TDD involves writing a failing test, making it pass with minimal code, and then improving the implementation. This methodology ensures robust, reliable Go code through iterative development.

How do I use golden files for Go testing?

Golden files store expected outputs for your Go functions, allowing tests to compare actual results against them. This pattern is useful for validating complex outputs without hardcoding lengthy expectations in your test code.

How do I run fuzz tests to validate Go input handling?

Fuzz tests in Go automatically generate random inputs to uncover edge cases and validate input handling. Writing fuzz tests involves passing a function to testing.F, which then mutates inputs to trigger crashes or failures.

Can I benchmark memory allocation in Go tests?

Yes, you can benchmark memory allocation in Go tests using the B.ReportAllocs function within your benchmark tests. This measures and reports the number of allocations per operation, helping optimize performance.

What is the best way to mock dependencies in Go tests?

The best way to mock dependencies in Go tests is through interface-based mocking. By defining interfaces for external dependencies, you can substitute real implementations with mocks to isolate the code under test.