Go test
A comprehensive skill catalog for AI agents
npx -y skills add G1Joshi/Agent-Skills --skill go-testAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 10 stars10 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Go testing package. Use for Go testing.
SKILL.md
1.7 KB, as published. Nobody here has run it
Go Test
Go has a built-in testing framework in the testing package. It follows Go's effective, minimalist philosophy: no magic, just code.
When to Use
- Go Projects: It is the standard. No 3rd party runner needed.
- Benchmarks: Built-in support (
func BenchmarkXxx(b *testing.B)).
Quick Start
// main_test.go
package main
import "testing"
func TestAdd(t *testing.T) {
got := Add(1, 2)
want := 3
if got != want {
t.Errorf("Add(1, 2) = %d; want %d", got, want)
}
}
Run with go test ./....
Core Concepts
Table Driven Tests
The idiomatic way to write Go tests. Define a slice of structs with input/output, then loop range over them.
tests := []struct {
input int
want int
}{
{1, 2},
{2, 4},
}
for _, tc := range tests {
t.Run("subtest", func(t *testing.T) { ... })
}
Subtests (t.Run)
Allows hierarchical test execution and reporting.
Helper Functions
Use t.Helper() in utility functions so that failure logs point to the test caller, not the helper line.
Best Practices (2025)
Do:
- Use
testify/assert: If you hateif got != want, use thetestifylibrary forassert.Equal(t, want, got). It's the most accepted "lib" extension. - Run with
-race:go test -race ./...to detect race conditions. - Parallelism: Use
t.Parallel()inside tests to speed up execution.
Don't:
- Don't use assertions for everything: Go prefers explicit error checking.
- Don't ignore errors: If a setup step fails, use
t.Fatalto stop the test immediately.