go-testinglisted
Install: claude install-skill dwana1/golang-skills
# Go Testing
Guidelines for writing clear, maintainable Go tests following Google's style.
## Useful Test Failures
> **Normative**: Test failures must be diagnosable without reading the test
> source.
Every failure message should include:
- What caused the failure
- The function inputs
- The actual result (got)
- The expected result (want)
### Failure Message Format
Use the standard format: `YourFunc(%v) = %v, want %v`
```go
// Good:
if got := Add(2, 3); got != 5 {
t.Errorf("Add(2, 3) = %d, want %d", got, 5)
}
// Bad: Missing function name and inputs
if got := Add(2, 3); got != 5 {
t.Errorf("got %d, want %d", got, 5)
}
```
### Got Before Want
Always print actual result before expected:
```go
// Good:
t.Errorf("Parse(%q) = %v, want %v", input, got, want)
// Bad: want/got reversed
t.Errorf("Parse(%q) want %v, got %v", input, want, got)
```
---
## No Assertion Libraries
> **Normative**: Do not create or use assertion libraries.
Assertion libraries fragment the developer experience and often produce
unhelpful failure messages.
```go
// Bad:
assert.IsNotNil(t, "obj", obj)
assert.StringEq(t, "obj.Type", obj.Type, "blogPost")
assert.IntEq(t, "obj.Comments", obj.Comments, 2)
// Good: Use cmp package and standard comparisons
want := BlogPost{
Type: "blogPost",
Comments: 2,
Body: "Hello, world!",
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("GetPost() mismatch (-want +got):\n%s", diff)
}
```
For domain-specific comparisons,