golang-testing

Standardize Go testing practices for unit, integration, fuzz, and benchmark coverage.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-testing-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-testing
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-testing-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill turns Go testing guidance into a practical workflow for writing reliable, maintainable, and production-ready tests. It helps you avoid flaky tests, hidden race conditions, weak assertions, and coverage that does not reflect real behavior.

Core Features & Use Cases

  • Table-driven unit tests: Structure cases with named subtests, parallel execution, and clear assertions.
  • Integration and concurrency testing: Separate integration suites with build tags, detect goroutine leaks, and verify race-prone code safely.
  • Behavior-focused testing: Use black-box package_test layouts, httptest for handlers, Example functions for documentation, and fuzz tests for critical functions.
  • Performance and quality workflows: Add benchmarks with allocation tracking, mock dependencies at the consumer boundary, and apply testify suites where organized setup and teardown are needed.
  • Use Case: A Go team can apply this Skill to review an existing test suite, generate new tests for handlers or services, and enforce reliable CI-ready practices across unit, integration, fuzz, and benchmark coverage.

Quick Start

Ask for a Go test plan or test implementation for your package, and specify whether you need unit tests, integration tests, concurrency checks, fuzzing, benchmarks, or a review of existing tests.

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 unit tests in Go with parallel execution?

Table-driven unit tests in Go use named subtests with t.Parallel to structure cases and execute them concurrently, ensuring clear assertions and reliable coverage. This approach standardizes test cases for maintainability and faster CI execution.

What is the best way to test HTTP handlers in Go without starting a server?

Testing HTTP handlers in Go without a live server uses httptest.NewRecorder to capture responses directly. This allows you to assert status codes and response bodies efficiently while mocking dependencies at the consumer boundary.

How do I detect goroutine leaks in my Go integration tests?

Detecting goroutine leaks in Go integration tests involves using goleak within build-tagged integration suites. This verifies race-prone code safely and prevents flaky tests caused by lingering background goroutines.

When should I use package_test for black-box testing in Go?

Use package_test for black-box testing in Go when you need to verify external behavior without accessing internal package state. This layout enforces true API coverage and prevents unexported variables from creating false test dependencies.

How do I add fuzz tests and benchmarks to a Go package?

Adding fuzz tests and benchmarks to a Go package involves creating Fuzz functions for critical inputs and benchmark functions with allocation tracking. This validates edge cases and measures performance impacts accurately.

Does this Go testing workflow support testify suites for setup and teardown?

This Go testing workflow supports testify suites where organized setup and teardown are needed. It applies testify alongside fake clocks and Example functions to maintain structured, documented, and reliable test environments.