go-testing
Skill9 starsChanged 8 months agoMITView on GitHub
Use when writing, reviewing, or debugging Go tests and benchmarks. Covers table-driven tests, parallel execution, go-cmp, T.Context, T.Chdir, b.Loop, synctest for deterministic concurrency testing, and test failure messages.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- AllThingsSmitty/proven-skillstheir own version, first seen Oct 6, 2026
- Integralist/agent-skillstheir own version, first seen Oct 4, 2026
- Dankosik/golang-backend-skillstheir own version, first seen Sep 8, 2026
- muratmirgun/gopherstheir own version, first seen Aug 11, 2026
- cxuu/golang-skillstheir own version, first seen Jun 20, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- cxuu/golang-skills★ 165same name
- muratmirgun/gophers★ 9same name
- Integralist/agent-skills★ 3same name
- AllThingsSmitty/proven-skills★ 1same name
- Dankosik/golang-backend-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository8 other files it gives its agents.
- golangSkill
- go-code-reviewSkill
- go-concurrencySkill
- go-error-handlingSkill
- go-lintingSkill
- go-performanceSkill
- go-project-layoutSkill
- go-securitySkill
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 90
No need to call b.ResetTimer()
- Very specific: line 154
Restrictions in synctest bubbles: Do not call t.Run(), t.Parallel(), or t.Deadline().
- Very specific: line 158
Prefer github.com/google/go-cmp/cmp over reflect.DeepEqual.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Testing
Production-grade testing patterns for Go.
Table-Driven Tests with Parallel Execution
func TestSplit(t *testing.T) {
tests := []struct {
name string
input string
sep string
want []string
}{
{name: "simple", input: "a/b/c", sep: "/", want: []string{"a", "b", "c"}},
{name: "empty", input: "", sep: "/", want: []string{""}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := strings.Split(tt.input, tt.sep)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("Split() mismatch (-want +got):\n%s", diff)
}
})
}
}T.Context and T.Chdir (Go 1.24+)
func TestWithContext(t *testing.T) {
// T.Context returns a context canceled after test completes
// but before cleanup functions run
ctx := t.Context()
result, err := doWork(ctx)
if err != nil {
t.Fatal(err)
}
}
func TestWithChdir(t *testing.T) {
// T.Chdir changes working directory for duration of test
// and automatically restores it after
t.Chdir("testdata")
data, err := os.ReadFile("input.txt")
// ...
}Benchmark with b.Loop (Go 1.24+)
// Old way - error prone
func BenchmarkOld(b *testing.B) {
input := setupInput() // counted in benchmark time!
b.ResetTimer()
for i := 0; i < b.N; i++ {
process(input) // compiler might optimize away
}
}
// Go 1.24+ - preferred
func BenchmarkNew(b *testing.B) {
input := setupInput() // setup runs once, excluded from timing
for b.Loop() {
process(input) // compiler cannot optimize away
}
}Benefits of b.Loop():
- Setup code runs exactly once per
-count, automatically excluded from timing - No need to call
b.ResetTimer() - Function call parameters and results are kept alive, preventing compiler optimization
Testing Concurrent Code with synctest (Go 1.25+)
The testing/synctest package provides deterministic testing for concurrent code using synthetic time.
import "testing/synctest"
func TestTimeout(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
defer cancel()
time.Sleep(4 * time.Second) // instant in real time
if err := ctx.Err(); err != nil {
t.Fatalf("unexpected timeout: %v", err)
}
time.Sleep(2 * time.Second)
if ctx.Err() != context.DeadlineExceeded {
t.Fatal("expected deadline exceeded")
}
})
}Key concepts:
synctest.Testcreates an isolated "bubble" with synthetic time- Time only advances when all goroutines in the bubble are blocked
synctest.Wait()waits for all goroutines to be durably blocked
func TestPeriodicTask(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
var count atomic.Int64
ctx, cancel := context.WithCancel(t.Context())
go func() {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
count.Add(1)
}
}
}()
time.Sleep(350 * time.Millisecond)
synctest.Wait()
cancel()
synctest.Wait()
if got := count.Load(); got != 3 {
t.Errorf("got %d ticks, want 3", got)
}
})
}Restrictions in synctest bubbles: Do not call t.Run(), t.Parallel(), or t.Deadline().
Use go-cmp for Comparisons
Prefer github.com/google/go-cmp/cmp over reflect.DeepEqual.
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
// With options
if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(User{})); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}Useful Test Failures
Include: what was wrong, inputs, actual result, expected result.
// Wrong
if got != want { t.Error("wrong result") }
// Correct
if got != want { t.Errorf("Foo(%q) = %d; want %d", input, got, want) }Use t.Fatal for Setup Failures
f, err := os.CreateTemp("", "test")
if err != nil {
t.Fatal("failed to set up test")
}Interfaces Belong to Consumers
Define interfaces in the package that uses them, not the package that implements them.
// Producer returns concrete type
package producer
type Thinger struct{}
func NewThinger() *Thinger { return &Thinger{} }
// Consumer defines interface it needs
package consumer
type Thinger interface { Thing() bool }
func Process(t Thinger) { }Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

