golang-testing

Implement Go tests with table-driven cases, subtests, benchmarks, and fuzzing.

6|Updated Mar 25, 2023
One-click install
npx skills add https://github.com/songkg7/dotfiles --skill golang-testing-songkg7
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/songkg7/dotfiles/tree/main/dot_claude/skills/golang-testing
Command: npx skills add https://github.com/songkg7/dotfiles --skill golang-testing-songkg7

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go developers often face challenges writing reliable tests that cover various inputs, edge cases, and performance concerns. This Skill provides practical patterns and guidance to implement effective tests in Go, aligned with a TDD workflow.

Core Features & Use Cases

  • Table-driven tests to cover multiple inputs succinctly.
  • Subtests and t.Run for organized, readable, and parallelizable test cases.
  • Benchmarks to measure performance and optimize code.
  • Fuzzing for input validation and robustness (Go 1.18+).
  • Guidance on integrating tests into Go projects from feature development to maintenance.

Quick Start

Create a new test file, write a failing test to drive implementation, run go test to observe failure, implement the minimal code to pass the test, then refactor while keeping tests green.

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 to cover multiple inputs?

Go benchmarks measure performance using the testing.B type and Benchmark functions to execute code repeatedly. They help optimize code by providing operation counts and allocation metrics during performance testing workflows.

How do I use fuzzing to test input validation in Go?

Go fuzzing tests input validation and robustness by automatically generating random inputs to find edge cases. Available in Go 1.18+, fuzzing complements table-driven tests by discovering unexpected panics and failures in your validation logic.

Do I need external testing libraries to implement TDD in Go?

You do not need external testing libraries to implement TDD in Go. The skill requires only the standard Go toolchain and standard testing packages to write failing tests, implement minimal code to pass, and refactor while keeping tests green.

What is the best way to organize Go subtests for better readability?

The best way to organize Go subtests is using t.Run within your test functions to create nested test cases. This approach provides organized, readable output and allows individual subtests to run in parallel, improving test execution efficiency.

When should I use benchmarks versus fuzzing in my Go tests?

Use benchmarks when you need to measure performance and optimize code execution speed, and use fuzzing when you need to validate input handling and robustness against unexpected data. Both integrate with the standard Go testing package within a TDD workflow.