go-cli-testing
Design, implement, stabilize, and review Go CLI tests across fresh command trees, pure logic, table-driven cases, streams, typed configuration, file…
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Go CLI Testing
Test observable behavior at the narrowest boundary that proves it. Isolate every
mutable resource and reserve executable tests for process-level semantics.
Core Workflow
- Inventory success, invalid, boundary, dependency-failure, and cancellation behavior.
- Map each case to a pure, command, adapter, integration, or binary test.
- Inject arguments, streams, configuration, clocks, and effectful dependencies.
- Isolate files, environment, servers, repositories, ports, and subprocesses.
- Assert stdout, stderr, exit behavior, and errors according to the public contract.
- Gate live or platform-specific tests and make their changes reversible.
- Run standard, race, tagged, and relevant platform checks.
- Execute every supported build profile and smoke-test final artifacts.
- Interpret coverage gaps without treating execution as behavioral proof.
Read Next
| Task | Load |
|---|---|
| Build or overhaul a CLI test suite | guidelines.md, workflows/test-cli-command.md |
| Stabilize a flaky asynchronous test | workflows/stabilize-flaky-test.md |
| Write focused command tests | references/cli-testing/rules.md, references/cli-testing/examples.md |
| Add subprocess, HTTP, repository, or integration tests | references/cli-testing/patterns.md |
| Review coverage, isolation, or flakiness | references/cli-testing/checklist.md |
| Choose the right test boundary | references/cli-testing/knowledge.md |
| Benchmark or profile performance | Use go-performance-testing |
Guardrails
- Do not mutate developer data or depend on fixed temporary paths and ports.
- Do not run parallel tests that replace process-global state.
- Replace timing sleeps with synchronization, deadlines, or fake clocks.
- Use
testing/synctestonly when the minimum Go version supports it and the
behavior fits an isolated bubble.
- Inspect wrapped errors structurally unless exact diagnostics are contractual.
- Prefer one valuable executable flow over many slow end-to-end tests.
- Construct a fresh command tree and typed configuration for every test.
- Assert both
Executeerrors and stream output.
Source Notes
Guidance is transformed and paraphrased from testing material throughout
Ricardo Gerardi, Powerful Command-Line Applications in Go (Pragmatic
Bookshelf, 2021), especially Chapters 1-7 and 11. Examples are original.
Book: https://pragprog.com/titles/rggo/powerful-command-line-applications-in-go/
Modern test APIs should be verified against https://pkg.go.dev/testing and the
current Go documentation before implementation.
Fresh command-tree, HTTP fake, configuration, and build-profile guidance also
incorporates transformed material from Marian Montagnino, *Building Modern CLI
Applications in Go* (Packt, 2023), especially Chapters 4, 6, and 11.
Subtest, coverage, parser, concurrency, HTTP server, and SQL adapter guidance
also incorporates transformed material from Inanc Gumus, *Go by Example:
Programmer's Guide to Idiomatic and Testable Programs* (Manning, 2025),
Chapters 2-10.
Test categorization, race/shuffle execution, deterministic time, iotest, and
benchmark-correctness guidance also incorporates transformed material from
Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022),
Chapter 11.
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/LVTD-LLC/skills/skills/go-cli-testing/SKILL.md