一键导入
testing-go
Go testing patterns for MCP Toolkit. Use this when writing or reviewing tests — table-driven tests, mocking, coverage thresholds, and E2E testing.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Go testing patterns for MCP Toolkit. Use this when writing or reviewing tests — table-driven tests, mocking, coverage thresholds, and E2E testing.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Common development tasks for MCP Toolkit. Use this when building, adding new servers, editors, CLI flags, or running the change checklist.
Architecture patterns for MCP Toolkit Go code. Use this when writing or reviewing Go functions — composable design, error handling, and dependency injection.
| name | testing-go |
| description | Go testing patterns for MCP Toolkit. Use this when writing or reviewing tests — table-driven tests, mocking, coverage thresholds, and E2E testing. |
Always prefer table-driven tests with testify:
func TestSomething(t *testing.T) {
tests := []struct {
name string
input string
want string
wantErr bool
}{
{"valid input", "input", "output", false},
{"empty input returns error", "", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Function(tt.input)
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
Mock at the interface boundary, not the implementation:
type mockRuntime struct{ available bool }
func (m *mockRuntime) Available() bool { return m.available }
func (m *mockRuntime) Name() string { return "mock" }
Keep mocks in the same _test.go file that uses them.
Use TestUnit_Scenario_ExpectedOutcome:
func TestDetectRuntime_NoRuntimes_ReturnsError(t *testing.T) { ... }
func TestDetectRuntime_DockerAvailable_ReturnsDocker(t *testing.T) { ... }
make coverage-check).E2E tests live in test/e2e/ and exercise the compiled binary:
func TestCLI_Version_PrintsVersion(t *testing.T) {
out, err := exec.Command(binary, "version").CombinedOutput()
assert.NoError(t, err)
assert.Contains(t, string(out), "mcp-toolkit")
}
Before marking a feature tested, verify: