go-testing

Applies focused Go testing patterns for unit tests, Bubbletea TUI flows, and golden files.

Updated Mar 7, 2026
One-click install
npx skills add https://github.com/albersg/dotfiles --skill go-testing-albersg
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-testing
Source: https://github.com/albersg/dotfiles/tree/main/dotfiles-opencode/.opencode/skills/go-testing
Command: npx skills add https://github.com/albersg/dotfiles --skill go-testing-albersg

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing consistent, maintainable Go tests is hard when projects mix pure functions, filesystem operations, TUI state machines, and rendered output. This Skill provides a decision framework that maps each code target to the right Go testing pattern, eliminating guesswork and inconsistent test styles. ## Core Features & Use Cases - Pattern Selection via Decision Gates: Maps code targets (pure functions, file operations, TUI state, rendered output, external commands) to the correct test pattern such as table-driven tests, teatest, or golden files. - Bubbletea/TUI Testing Guidance: Distinguishes when to call Model.Update() directly versus when to use teatest.NewTestModel() for full interactive flows. - Golden File Discipline: Enforces deterministic golden files updated only through the repo's -update flag, with verification reruns. - Use Case: When adding coverage to a Go CLI with a Bubbletea interface, load this Skill to decide test patterns per component, write scenario-named cases, and run narrow package tests before broader suites. ## Quick Start Ask the AI to write tests for a Go function or Bubbletea model using the go-testing patterns, for example by requesting table-driven tests with coverage for a specific package.

Frequently Asked Questions about go-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write table-driven tests in Go?▼

Define a slice of anonymous structs with name, input, and expected fields, then loop with t.Run(tt.name, ...) for each case. Name cases by scenario rather than input mechanics, and assert outputs, errors, and side effects explicitly.

How to test a Bubbletea TUI model in Go?▼

Test state transitions by calling Model.Update() directly with a tea.Msg and asserting the resulting model state. Use teatest.NewTestModel() only for full interactive flows where you need to send messages and wait for completion.

When should I use teatest vs direct Update calls?▼

Use direct Model.Update() calls for testing state transitions, since they are fast and deterministic. Reserve teatest for full interactive flows that require message sending, waiting with WaitFinished, and inspecting the final model.

How do golden file tests work in Go?▼

Golden tests compare rendered output against a stored file, with an -update flag that rewrites the file when output intentionally changes. Always rerun tests without -update after regenerating, and keep golden files deterministic.

How do I test Go code that runs external commands?▼

Wrap system or command execution behind small interfaces or mocks for unit tests. For tests that run real external commands, mark them as integration tests and skip them with testing.Short() so go test -short stays fast.

Why should Go filesystem tests use t.TempDir?▼

t.TempDir() creates an isolated temporary directory that Go cleans up automatically, preventing tests from depending on or polluting the real home directory. This keeps filesystem tests hermetic and safe to run in parallel.