go-testing

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

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

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 decision gates and hard rules so every test follows the right pattern for the behavior under test. ## Core Features & Use Cases - Pattern selection via decision gates: maps each test target (pure function, error behavior, file operations, TUI state, rendered output, external commands) to the correct Go testing pattern. - Bubbletea and teatest guidance: tests Model.Update() directly for state transitions and reserves teatest for full interactive flows. - Golden file discipline: enforces deterministic golden files updated only through the repo's -update flag, with a rerun verification step. - Use Case: When adding coverage to a Go CLI built with Bubbletea, use this Skill to write table-driven unit tests for parsers, direct Update() tests for screen transitions, and golden file tests for rendered views. ## Quick Start Ask the assistant to write Go tests for a specific package or function following table-driven, Bubbletea, and golden file patterns.

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, want, and wantErr fields, then loop with t.Run(tt.name, ...) executing the function and asserting outputs and errors. Name cases by scenario rather than input mechanics for readable failure output.

How to test Bubbletea TUI applications in Go?▼

Test Model.Update() directly by passing tea.Msg values like tea.KeyMsg and asserting the returned model's state transitions. Use teatest.NewTestModel() only for full interactive flows where you need to send messages and wait for the program to finish.

What is the difference between teatest and direct Update testing?▼

Direct Update() calls test pure state transitions synchronously and are fast and deterministic. teatest runs the full Bubbletea program loop, which suits end-to-end interactive flows but is slower and harder to debug.

How do golden file tests work in Go?▼

Compare rendered output against a stored file, regenerating it only through a -update flag defined with flag.Bool. After updating, inspect the diff and rerun tests without -update to confirm the golden files match.

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

Wrap command execution behind small interfaces or mocks for unit tests. For real external commands, write integration tests guarded by testing.Short() so they are skipped when running go test with the -short flag.

Why should filesystem tests use t.TempDir in Go?▼

t.TempDir creates an isolated temporary directory that Go cleans up automatically after the test, preventing cross-test pollution. It avoids relying on a real home directory, which makes tests non-deterministic across machines.