golang-testing

Automate Go test setup with table-driven tests and testify assertions.

3|Updated Jul 13, 2020
One-click install
npx skills add https://github.com/nieomylnieja/dotfiles --skill golang-testing-nieomylnieja
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/nieomylnieja/dotfiles/tree/main/config/agents/skills/golang-testing
Command: npx skills add https://github.com/nieomylnieja/dotfiles --skill golang-testing-nieomylnieja

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing and maintaining Go tests, benchmarks, and test helpers can be error-prone and time-consuming without consistent style and API usage guidance.

Core Features & Use Cases

  • Guidelines for test organization, table-driven tests with subtests, and proper use of t.Run, t.Helper, and t.Parallel.
  • Recommendations for using testify's require and assert to ensure deterministic failures and clear messaging.
  • Go-version aware practices and fixture management with testdata to ensure compatibility across Go releases.

Quick Start

Set up a Go test suite that uses table-driven tests with subtests and parallel execution.

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 with subtests in Go?

Table-driven tests in Go use t.Run to execute subtests, allowing structured iteration over test cases. You define test cases in a slice and loop through them, passing each case to t.Run for isolated execution and clear failure reporting.

When should I use t.Helper and t.Parallel in Go testing?

Use t.Helper to mark test utility functions so failures point to the caller, and t.Parallel to signal that a test can run concurrently. They improve error readability and reduce execution time for independent test cases.

What is the difference between require and assert in Go tests?

Require stops test execution immediately on failure, while assert records the failure and continues. Use require for conditions that make subsequent assertions meaningless, and assert to collect multiple failure results in one test.

How do I manage test fixtures and testdata in Golang projects?

Test fixtures in Go are managed using a testdata directory, storing input files and expected outputs. This convention keeps test resources organized and accessible, ensuring compatibility across different Go releases.

How do I write and run benchmarks in Go?

Go benchmarks use functions prefixed with Benchmark to measure performance. They execute repeatedly to gather stable timing data, helping identify regressions and optimize code paths within table-driven test structures.

Can I use testify assertions with table-driven Go tests?

Yes, testify assertions integrate seamlessly with table-driven Go tests. You can use require and assert within t.Run subtests to enforce deterministic failures and clear messaging for each test case iteration.