go-test

Provide Go test design guidelines covering naming, table-driven tests, and parallel execution.

Updated May 2, 2020
One-click install
npx skills add https://github.com/vankichi/dotfiles --skill go-test-vankichi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-test
Source: https://github.com/vankichi/dotfiles/tree/main/claude/ja/skills/go-test
Command: npx skills add https://github.com/vankichi/dotfiles --skill go-test-vankichi

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps developers write clean, maintainable, and efficient Go test code. It provides a comprehensive reference for naming conventions, table-driven tests, parallel execution, race detectors, and more.

Core Features & Use Cases

  • Naming Conventions: Guidelines for naming test functions, tables, and helper functions.
  • Table-Driven Tests: Best practices for writing table-driven tests, including structuring data and handling errors.
  • Parallel Execution: How to use t.Parallel() effectively to speed up test execution.
  • Race Detectors: Techniques for identifying and fixing race conditions in concurrent code.
  • Test Design Techniques: Black-box vs. white-box testing, boundary value analysis, equivalence partitioning, and more.
  • Mocking and Stubbing: Strategies for using fakes, stubs, and mocks to isolate tests.
  • Test Fixtures and Data: How to create and use test fixtures and golden files.
  • Test Organization: Unit tests, integration tests, and end-to-end tests with examples.

Quick Start

Run the go-test skill to review and improve your Go test code.

Frequently Asked Questions about go-test

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 struct slice to define test cases and loop over them with t.Run. Best practices include structuring test data clearly and handling expected errors within the subtest closure to ensure maintainable test logic.

How does parallel test execution work in Go testing?

Parallel test execution in Go uses t.Parallel() to run subtests concurrently. This speeds up test execution significantly, but requires careful handling of shared state and variables to avoid race conditions across concurrent test cases.

What is the best way to detect race conditions in Go tests?

Race detection in Go tests involves using the race detector to identify concurrent code issues. Techniques include running tests with the race flag enabled and properly isolating shared data using synchronization primitives or mocks to ensure thread safety.

Do I need to understand concurrent programming to use Go test best practices?

Yes, a basic understanding of concurrent programming and the Go testing package is required. This knowledge is necessary to effectively apply parallel execution, handle race detection, and implement black-box versus white-box test design techniques.

How do I isolate tests using mocks and stubs in Go?

Isolating Go tests involves using fakes, stubs, and mocks to replace real dependencies. This strategy ensures unit tests remain focused and reliable by preventing external side effects and controlling the behavior of underlying components.

When should I use black-box testing versus white-box testing in Go?

Black-box testing checks external behavior without knowing internal structures, while white-box testing verifies internal logic. Equivalence partitioning and boundary value analysis help decide the approach based on whether internal code paths need validation.