一键导入
testing-patterns
Test implementation patterns. Use this when writing tests — table-driven tests, mocking, fixtures, assertions, and parallel execution.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Test implementation patterns. Use this when writing tests — table-driven tests, mocking, fixtures, assertions, and parallel execution.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Resolve GitHub PR review comments safely, read unresolved comments, validate each issue, make minimal fixes, test, commit, and resolve.
Use zero-install context minimization first, with optional local optimization tooling when available.
Accessibility review for semantic HTML, ARIA, keyboard support, focus, screen readers, contrast, and WCAG-oriented issues.
API and contract review for OpenAPI/AsyncAPI/protobuf changes, backwards compatibility, schemas, status codes, and examples.
Architecture review for SOLID, layering, boundaries, coupling, cohesion, extensibility, and maintainability.
Backend review for handlers, services, validation, errors, transactions, dependency boundaries, and service contracts.
| name | testing-patterns |
| description | Test implementation patterns. Use this when writing tests — table-driven tests, mocking, fixtures, assertions, and parallel execution. |
Prefer table-driven tests when testing the same function across multiple scenarios:
tests := []struct {
name string
input InputType
want OutputType
wantErr bool
}{
{"valid input", validInput, expectedOutput, false},
{"empty input returns error", emptyInput, zero, true},
{"boundary value", boundaryInput, boundaryOutput, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := FunctionUnderTest(tt.input)
// assert based on tt.wantErr, tt.want
})
}
Mock at the interface boundary, not the implementation:
// Define a small interface for the dependency
type DataStore interface {
Get(key string) (string, error)
}
// Create a mock that implements the interface
type mockStore struct {
data map[string]string
err error
}
Keep mocks in the same test file that uses them. Never mock what you own — test your own code with real implementations when possible.
Extract repetitive setup into named helper functions:
t.Helper() in Go).Use assertion libraries for readable failure messages:
assertEqual(expected, actual) — value comparison.assertError(err) — confirms failure path.assertNoError(err) — confirms success path.assertContains(haystack, needle) — partial match.