golang-testing

Apply table-driven tests, testify suites, mocks, and goleak detection to Go projects.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/osmanozen/go-commerce --skill golang-testing-osmanozen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/osmanozen/go-commerce/tree/main/.agents/skills/golang-testing
Command: npx skills add https://github.com/osmanozen/go-commerce --skill golang-testing-osmanozen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing robust and maintainable Go tests can be time-consuming and error-prone without agreed patterns. This Skill guides developers on best practices for table-driven tests, test suites with testify, mocks, integration tests, benchmarks, and CI integration to improve reliability and speed.

Core Features & Use Cases

  • Provides structured guidelines for unit, integration, and benchmark tests in Go.
  • Demonstrates safe testing patterns: named subtests with t.Run, t.Parallel, and proper mock usage via interfaces.
  • Helps teams implement goroutine leak detection with goleak, fuzz testing, and snapshot testing to prevent flaky tests.

Quick Start

Explain how to implement Go testing best practices in a Golang project.

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 improve test maintainability?

Table-driven tests in Go improve maintainability by structuring test cases in slices and executing them through named subtests with t.Run, keeping inputs and expected outputs cleanly separated for easier updates and parallel execution.

What is the best way to detect goroutine leaks in Go tests?

Detect goroutine leaks in Go tests by integrating goleak in TestMain, which verifies that all goroutines spawned during test execution properly terminate, ensuring clean and deterministic test suites.

Can I use testify suites for structuring complex Go integration tests?

Yes, testify suites support structuring complex Go integration tests by grouping related test methods into structs with shared setup and teardown logic, combining well with build tags to isolate integration test execution.

How do I mock interfaces in Go tests without coupling to implementation details?

Mock interfaces in Go tests by defining mock implementations of your interfaces, allowing you to isolate dependencies and verify interactions while avoiding coupling to internal implementation details for robust unit tests.

Does this Go testing approach support fuzzing and benchmarking in CI workflows?

Yes, this Go testing approach supports fuzzing and benchmarking within CI workflows by applying established patterns for deterministic test execution, ensuring reliable performance measurements and edge-case discovery across project sizes.

Why should I use named subtests with t.Parallel in my Go test suites?

Named subtests with t.Parallel improve Go test suite execution speed by running independent test cases concurrently, while providing granular test output that isolates failures and prevents flaky tests through proper isolation.