一键导入
go-unit-test
Style rules for writing Go unit tests. Load whenever writing or modifying *_test.go files.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Style rules for writing Go unit tests. Load whenever writing or modifying *_test.go files.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Create, edit, comment on, and label GitHub issues following the project's style
Implement gpsprot high-level (device-independent) configuration - the ConfigProtocol/Configurator - for a new GPS receiver protocol family
Build systematic collection of packet logs for a GPS receiver, covering all implemented decode paths per plan/packet-testing.md
Drive a test satpulsed instance from a recorded packet log, with no GPS hardware, by replaying the log through a FIFO with original packet pacing. Use to exercise the full scan/decode/event pipeline or the web interface from a capture.
End-to-end test of GPS message (gpsprot.*Msg) pipeline with GPS hardware
Stand up a throwaway satpulsed instance as an unprivileged user for testing, fed from a serial device or a FIFO. Use directly to run a test instance, or as the setup step for the drive-satpulsed-from-log and hardware-test-gps-msgs skills.
基于 SOC 职业分类
| name | go-unit-test |
| description | Style rules for writing Go unit tests. Load whenever writing or modifying *_test.go files. |
| allowed-tools | Bash, Glob, Grep, Read, Edit, Write |
Wherever practical, make tests table-driven and use reflect.DeepEqual to compare whole expected values rather than individual fields.
Use table-driven tests wherever possible. One table of test cases per test function.
Each test case struct should have fields for the inputs and the expected outputs.
A test case can have multiple input fields and multiple expected output fields.
Prefer expect as the prefix for expected-value fields (e.g. expect, expectErr).
func TestFoo(t *testing.T) {
tests := []struct {
name string
input InputType
expect OutputType
}{
{
name: "description of case",
input: InputType{...},
expect: OutputType{...},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := Foo(tc.input)
if !reflect.DeepEqual(got, tc.expect) {
t.Errorf("got %+v\nwant %+v", got, tc.expect)
}
})
}
}
Do not compare struct fields individually. Put the complete expected value in the test table and compare the whole thing with reflect.DeepEqual.
Bad:
if got.X != 1 { t.Errorf(...) }
if got.Y != 2 { t.Errorf(...) }
Good:
if !reflect.DeepEqual(got, tc.expect) {
t.Errorf("got %+v\nwant %+v", got, tc.expect)
}
Use t.Fatalf for errors that prevent further testing (setup failures, parse errors).
Use t.Errorf for assertion failures (DeepEqual comparisons).
For tests that expect errors, add an expectErr bool field to the table:
if tc.expectErr {
if err == nil {
t.Fatalf("expected error")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Use only the standard testing package and reflect.DeepEqual. Do not use testify or other assertion libraries.