

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456# Go Test Best Practices78## Go Version9- Use Go 1.24+ features in tests10- Reference: @https://tip.golang.org/doc/go1.2411- Key testing improvements:12 - t.Cleanup() for test cleanup13 - t.TempDir() for managing temp dirs14 - t.Setenv() for scoped environment variables15 - b.Loop() for benchmarks (Go 1.24)16 - go test -fuzz for fuzzing17 - go vet now detects test misuses (Go 1.24)1819## Test Function Conventions20- All test functions must follow correct naming and signature:21 - Unit tests: `func TestXxx(t *testing.T)`22 - Benchmarks: `func BenchmarkXxx(b *testing.B)`23 - Fuzz tests: `func FuzzXxx(f *testing.F)`24- Avoid misnamed or malformed test functions – go vet will catch these in Go 1.24+25- Keep test functions short, focused, and readable2627## Table-Driven Tests28- Use table-driven style for variations of the same logic29- Use subtests (`t.Run(name, func(t *testing.T))`) for each case30- Always call `t.Parallel()` within subtests if test cases are independent31- Prefer descriptive names in subtests for easier debugging3233## Test Utilities and Cleanups34- Use `t.Cleanup()` to register cleanup logic in tests35- Use `t.TempDir()` instead of manual temp file management36- Use `t.Setenv(key, value)` for setting env vars in test scope37- Avoid manual cleanup with `defer os.Remove(...)` unless absolutely needed3839## Benchmarking40- Use `b.ReportAllocs()` to track memory allocations in benchmarks41- Use `b.ResetTimer()` before measuring just-in-time workloads42- Prefer `b.Loop()` over `for i := 0; i < b.N; i++` (Go 1.24+)43- Keep benchmark logic minimal and representative4445## Fuzzing (Go 1.18+)46- Use `FuzzXxx(f *testing.F)` to test parsers and data consumers47- Add seed inputs via `f.Add(...)` to initialize coverage48- Fuzz tests should validate invariants and panic conditions49- Always check and minimize corpus growth5051## Assertions and Error Checks52- Avoid panics in tests – use `t.Fatal`, `t.Error`, `t.Fatalf`, `t.Errorf`53- Use table-driven want vs got comparisons54- Clearly format failure messages: `t.Errorf("expected %v, got %v", want, got)`55- Consider using helper functions to reduce repetitive checks5657## Parallel Testing58- Use `t.Parallel()` for top-level test functions where safe59- Always use inside subtests when possible60- Avoid global state mutation in parallel tests61- Protect shared state with sync primitives if required6263## Logging and Debugging64- Use `t.Log` / `t.Logf` for test-local logs65- Avoid `fmt.Println()` in tests – not tied to test output66- Prefer structured test logs when debugging complex cases6768## Temp Files & Directories69- Use `t.TempDir()` for temp paths70- Prefer `filepath.Join(t.TempDir(), "file.txt")` over hardcoded temp paths71- Avoid manually cleaning up temp files – use Go's built-in cleanup7273## Environment Handling74- Use `t.Setenv()` for environment variable setup in tests75- Avoid modifying `os.Setenv` directly unless cleaned up properly76- Test behavior under different env configs using subtests7778## Test Organization79- Keep tests near the code they test (same package, _test.go file)80- Group related tests together using sections or subtests81- Use helper functions ending in _test.go to avoid export issues82- Avoid logic in test files that is not directly test-related8384## Linting & Vetting85- Run go vet on all test files – especially with Go 1.24+ analyzers86- Enable linters:87 - testpackage: avoid logic in test files88 - gocognit: test complexity89 - errcheck: all errors must be checked90 - staticcheck: catch subtle test issues91- Use go test -race for all concurrent test suites9293## Observability in Tests94- Log context IDs or test metadata using t.Log for traceability95- Capture test-specific logs and metrics via mocks or test sinks96- Prefer context-aware testing when mocking services9798## Using Testify99100### Testify/Assert101- Import with `import "github.com/stretchr/testify/assert"`102- Use for readable test assertions: `assert.Equal(t, expected, actual, "optional message")`103- Key assertion functions:104 - `assert.Equal(t, expected, actual)` - Check for equality105 - `assert.NotEqual(t, notExpected, actual)` - Check for inequality106 - `assert.True(t, value)` / `assert.False(t, value)` - Check boolean values107 - `assert.Nil(t, value)` / `assert.NotNil(t, value)` - Check for nil108 - `assert.NoError(t, err)` / `assert.Error(t, err)` - Check error values109 - `assert.Contains(t, collection, element)` - Check containment110 - `assert.Subset(t, superSet, subSet)` - Check subset relationships111- Use `require` instead of `assert` when test should abort on failure:112 - `require.NoError(t, err)` - Test will abort if error is not nil113 - Import with `import "github.com/stretchr/testify/require"`114- Prefer assertion error messages that provide context:115 - `assert.Equal(t, expected, actual, "should match after transformation")`116117### Testify/Mock118- Import with `import "github.com/stretchr/testify/mock"`119- Create mock structs that embed `mock.Mock`120- Define expectations before running the function under test:121 - `mockObj.On("MethodName", arg1, arg2).Return(returnVal1, returnVal2)`122- Verify expectations after test with `mockObj.AssertExpectations(t)`123- For specific call counts: `mockObj.On("MethodName", mock.Anything).Return(true).Times(3)`124- Match any argument with `mock.Anything` or `mock.AnythingOfType("string")`125- Use custom matchers with `mock.MatchedBy(func(arg Type) bool { ... })`126- Capture arguments with `mock.On(...).Run(func(args mock.Arguments) { ... })`127- Structure test with clear setup, execution, and assertion phases128129### Testify Best Practices130- Combine with table-driven tests for maximum readability131- Avoid excessive mocking - mock only external dependencies132- Use testify consistently across test suite for uniformity133- For complex mock setup, use helper functions to improve readability134- Consider using testify/suite for tests that share setup/teardown135- Use `assert.Subset()` and `assert.ElementsMatch()` for collection comparison136- For API testing, use testify with httptest package137138## Modern Patterns to Prefer139- ✅ Use `t.Parallel()` and `t.Run()` for better concurrency140- ✅ Use `t.Cleanup()` over manual defer cleanup141- ✅ Use `t.Setenv()` over os.Setenv142- ✅ Use `b.Loop()` over manual for i := 0; i < b.N; i++143- ✅ Use fuzzing for complex input functions144- ✅ Always check errors explicitly, even in tests145- ✅ Use testify/assert for clear test assertions146- ✅ Use testify/mock for clean dependency mocking
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| tphakala/birdnet-go.cursor/rules/database.mdc · 1.6k | Cursor rules | databasedo-not | 45/100 | today | |
| tphakala/birdnet-go.cursor/rules/frontend.mdc · 1.6k | Cursor rules | dependenciesuido-not | 61/100 | today | |
| tphakala/birdnet-go.cursor/rules/go.mdc · 1.6k | Cursor rules | buildteststylearch+5 | 69/100 | today | |
| tphakala/birdnet-goAGENTS.md · 1.6k | AGENTS.md | teststylegitdo-not+1 | 78/100 | today | |
| tphakala/birdnet-goCLAUDE.md · 1.6k | CLAUDE.md | buildtestlint-formatstyle+8 | 100/100 | today | |
| tphakala/birdnet-gofrontend/CLAUDE.md · 1.6k | CLAUDE.md | setuptestlint-formatstyle+7 | 84/100 | today | |
| tphakala/birdnet-gofrontend/src/lib/desktop/components/CLAUDE.md · 1.6k | CLAUDE.md | teststylearchui | 70/100 | today | |
| tphakala/birdnet-gofrontend/src/lib/desktop/components/ui/CLAUDE.md · 1.6k | CLAUDE.md | styleuidocs | 54/100 | today | |
| tphakala/birdnet-gofrontend/src/lib/desktop/features/settings/CLAUDE.md · 1.6k | CLAUDE.md | buildstylearchtypes+2 | 66/100 | today | |
| tphakala/birdnet-gofrontend/static/messages/CLAUDE.md · 1.6k | CLAUDE.md | archuido-notagent-behaviour | 67/100 | today | |
| tphakala/birdnet-gofrontend/tools/CLAUDE.md · 1.6k | CLAUDE.md | no sections | 65/100 | today | |
| tphakala/birdnet-gointernal/CLAUDE.md · 1.6k | CLAUDE.md | buildteststylearch+5 | 88/100 | today | |
| tphakala/birdnet-gointernal/api/v2/CLAUDE.md · 1.6k | CLAUDE.md | teststylesecurityapi+1 | 84/100 | today | |
| tphakala/birdnet-gointernal/errors/CLAUDE.md · 1.6k | CLAUDE.md | styleuiperformancedo-not+1 | 61/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| bybren-llc/safe-agentic-workflow.cursor/rules/10-backend-python.mdc · 399 | Cursor rules | testlint-formatstylegit+4 | 97/100 | today |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/tphakala-birdnet-go-cursor-rules-go-test)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.