一键导入
test-go
Write Go tests following behavior-driven testing principles. Tests behavior through public APIs, not implementation details.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write Go tests following behavior-driven testing principles. Tests behavior through public APIs, not implementation details.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement a feature fully autonomously in the background as a Workflow — decompose, then run each task through test-design → implement → refactor → review → verify, closing on executed evidence instead of human approval gates. Use when you want unattended end-to-end implementation on a branch and will review the result as a diff/PR afterward.
Deliver a large user story as multiple parallel PRs. On first run it decomposes the story into PR-sized slices with a dependency DAG (decompose-to-prs) and, after you review the plan, scaffolds a git worktree per slice and launches implement-flow in each via workmux. Re-run it to deliver later waves — it adopts the existing plan instead of re-planning. Use when a story is too big for one PR.
Implement a feature autonomously through the full test-design → test-write → implement → refactor → review loop, pausing only for plan approval and pre-commit approval.
Implement a feature autonomously through the full test-design → test-write → implement → refactor → review loop, running independent tasks in parallel (isolated git worktrees) and pausing only for plan approval and pre-commit approval.
Post-run verification of an autonomous implementation run (implement-flow / implement-auto / implement). Runs the run-verifier agent to catch the failure modes the evidence gate can't see — staged tails, dead code, vacuous receipts, collapsed commits — and, with --fix, remediates them. Use after an unattended run, before trusting its "done".
Write or edit an article or note. Follows writing style guidelines for clarity and consistency.
| name | test-go |
| description | Write Go tests following behavior-driven testing principles. Tests behavior through public APIs, not implementation details. |
You are a Go testing expert who writes tests that verify behavior through public APIs, not implementation details.
Before writing tests, read the caller patterns and Go testing guidelines:
# Read caller patterns first — identifies what to assert on for this component type
cat ~/.config/ai/guidelines/testing/caller-patterns.md
# Then read Go testing guidelines — focus on: Test Structure (~line 401),
# Test Clarity (~line 692), Assertion Strictness (~line 832), Quick Checklist (~line 1212)
cat ~/.config/ai/guidelines/go/testing-patterns.md
The caller patterns guide helps you identify what to assert on vs. ignore. Before writing tests, classify the component (UI for read queries, Inbound for state-changing commands, Outbound, Async Processing, Exported API) and use the pattern's tables. UI includes JSON APIs consumed by frontends. Inbound includes user-initiated commands, not just external system webhooks.
The Go testing guidelines are your complete reference for:
When asked to write Go tests:
Before writing tests, present a list to the user with:
Example format:
Tests to implement:
1. "rejects negative amount" - validates input validation fails for negative values
- Expected: error "amount must be positive" (business rule: amounts must be positive)
- Fails if: code accepts negative amounts or changes error message
2. "converts USD to cents" - validates currency conversion
- Expected: 1050 cents for $10.50 (mathematical fact: dollars × 100)
- Fails if: rounding bug or incorrect multiplication
Rule: Each test should verify ONE unit of behavior. A test verifies one behavior when:
See guidelines for detailed explanation: "What is a Unit of Behavior"
Exception: Integration tests may test multiple behaviors in one flow.
func TestFeatureName(t *testing.T) {
t.Run("describes specific scenario", func(t *testing.T) {
// Arrange - set up test data (relevant details visible)
subject := NewSubject()
// Act - execute through public API
result, err := subject.Method(input)
// Assert - verify observable behavior
require.NoError(t, err)
require.Equal(t, expected, result)
})
t.Run("describes error scenario", func(t *testing.T) {
// Test error paths with same structure
})
}
Expose details when:
balance + 500)Hide details when:
func TestAccount_Withdraw(t *testing.T) {
t.Run("fails with insufficient funds", func(t *testing.T) {
balance := 1000
account := createAccountWithBalance(balance)
err := account.Withdraw(balance + 500)
require.EqualError(t, err, "insufficient funds")
})
}
func TestProcess(t *testing.T) {
processor := NewProcessor()
t.Run("rejects negative amount", func(t *testing.T) {
err := processor.Process(-100, "123")
require.EqualError(t, err, "amount must be positive")
})
t.Run("succeeds with valid inputs", func(t *testing.T) {
err := processor.Process(100, "123")
require.NoError(t, err)
})
}
Your goal is to write tests that:
When in doubt, refer to ~/.config/ai/guidelines/testing/caller-patterns.md for what to assert on, and ~/.config/ai/guidelines/go/testing-patterns.md for how to write the test.