golang-testing

Create Go unit tests with table-driven cases and subtests.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill golang-testing-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/golang-testing
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill golang-testing-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you produce dependable Go test suites that catch regressions early and support maintainable development through clear TDD workflows.

Core Features & Use Cases

  • Table-driven tests for broad coverage: Validate many input/output scenarios with compact, readable cases (including error-paths).
  • Subtests and parallel execution: Organize related behaviors under a single test function while keeping them structured and optionally concurrent.
  • Testing tools for quality: Use helpers (t.Helper), temp resources (t.TempDir), golden files, mocks via interfaces, benchmarks, fuzzing, and coverage reports.
  • HTTP handler testing: Verify request/response behavior with httptest for web APIs and health endpoints.
  • Use Case: You’re implementing a user service and want fast feedback: create unit tests with table-driven cases for parsing and business rules, mock repositories for isolation, and add handler tests to ensure correct status codes and JSON responses.

Quick Start

Use the skill to design and run Go tests for your next function using a RED-GREEN-REFACTOR loop, starting with table-driven cases and subtests for both success and error paths.

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 for multiple input scenarios?

Go subtests organize related behaviors under a single test function using the t.Run method. This structure keeps tests readable and allows optional concurrent execution by calling t.Parallel within individual subtests.

How do I test HTTP handlers in Go using httptest?

Fuzzing in Go testing automatically generates randomized inputs to discover unexpected edge cases and crashes. You apply standard go test commands to execute fuzz targets, ensuring your program handles a wide range of data without regressions.

What is the best way to mock repositories for isolated Go unit testing?

Mocking repositories via interfaces is the best way to isolate Go unit tests. By defining interfaces for your data dependencies, you can inject mock implementations to verify business logic without hitting actual databases.

How do I generate coverage reports and benchmarks using go test?

You generate coverage reports and benchmarks using standard go test and go bench commands. These tools measure code execution paths and performance, helping you identify untested logic and track speed regressions across your workflows.