go-testing

Write table-driven Go tests, Bubbletea teatest flows, and golden file assertions.

Updated Aug 25, 2026
One-click install
npx skills add https://github.com/CarlosWilliamsR/SketchOS --skill go-testing-carloswilliamsr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-testing
Source: https://github.com/CarlosWilliamsR/SketchOS/tree/main/.config/opencode/skills/go-testing
Command: npx skills add https://github.com/CarlosWilliamsR/SketchOS --skill go-testing-carloswilliamsr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing consistent, maintainable Go tests requires choosing the right pattern for each scenario—unit tests, TUI state transitions, interactive flows, or golden files—and this Skill provides decision gates and proven patterns so tests cover behavior rather than implementation trivia. ## Core Features & Use Cases - Pattern Selection via Decision Gates: Maps each test target (pure functions, file operations, TUI state, rendered output, external commands) to the correct Go testing pattern. - Bubbletea and teatest Coverage: Distinguishes direct Model.Update() state testing from full interactive flows using teatest.NewTestModel(). - Golden File Discipline: Enforces deterministic golden files updated only through the -update flag, with verification runs afterward. - Use Case: When adding tests to a Go CLI with a Bubbletea TUI, use this Skill to write table-driven unit tests for parsers, direct Update tests for screen transitions, and golden file tests for rendered output. ## Quick Start Ask the AI to write tests for a specific Go package or Bubbletea model following the go-testing patterns, for example: write table-driven tests for my parser package and a teatest flow for the main menu navigation.

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, ...) executing the function and asserting results. Name cases by scenario rather than input mechanics, and include explicit success and failure cases for error behavior.

How to test Bubbletea TUI applications 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 send messages and wait for the program to finish.

When should I use teatest vs direct Model.Update testing?

Use direct Model.Update() calls for state transitions since they are fast and deterministic. Reserve teatest for full interactive flows that require the running program loop, such as verifying final output after a sequence of key messages.

How do golden file tests work in Go?

Store expected rendered output in files and compare against actual output in tests. Add an -update flag that rewrites golden files, run with -update to refresh them, inspect the diff, then rerun without -update to confirm the tests pass.

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 after the test, preventing tests from depending on or polluting the real home directory. This keeps filesystem tests deterministic and safe to run in parallel.