go-testing
Write and review Go unit, contract, transport, race, fuzz, and deterministic concurrency tests. Use for new behavior, bug fixes, flaky tests, and public API parity evidence.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- go-testing
- description
- Write and review Go unit, contract, transport, race, fuzz, and deterministic concurrency tests. Use for new behavior, bug fixes, flaky tests, and public API parity evidence.
03 SKILL.md 正文
Go testing
Read Documentation/project-context.md and .cratis/ai/rules/go.md first.
Use standard testing, not translated C# BDD infrastructure or coverage quotas.
Workflow
- Derive success, failure, boundary, cancellation, and cleanup cases from the contract. For a port, identify C# source/tests and stable cross-language data.
- Choose small fakes at consumer boundaries and real implementations where affordable. Keep external-package tests for public workflows.
- Use named table subtests when assertions are shared; otherwise split tests.
Use
t.Helper,t.Cleanup, andt.TempDir; isolate mutable state beforet.Parallel. UseT.Contextonly at Go 1.24+ and heed cleanup ordering. - Compare errors with
errors.Is/As, domain values semantically, protobufs withproto.Equalor protobuf-aware diffs, and wire output with contract fixtures. Do not rely on unstable map iteration or incidental error strings. - Use
httptestfor HTTP andbufconnfor actual gRPC serialization/status tests. Add real networking/TLS coverage for guarantees those cannot prove. - Synchronize concurrent tests explicitly. At Go 1.25+, use
testing/synctestfor fake-time in-memory work; real network I/O is not durably blocked fake time. Test early consumer exit, canceled blocked operations, joins, and ownership. - Fuzz deterministic decoders with seed corpora, preserving discovered failures.
Bound runs, for example
go test ./path -fuzz=FuzzDecode -fuzztime=15s. Run one fuzz target/package at a time; ordinary tests still run fuzz seeds. - Run focused tests while iterating, then the repository's gates including
go test -race ./.... Benchmarks require a question;B.Loopneeds Go 1.24+.
Small example: semantic table tests
This standard-library example demonstrates naming and error identity, rather than claiming a Cratis parser API exists.
package parsing_test
import (
"errors"
"strconv"
"testing"
)
func TestParseInt(t *testing.T) {
cases := []struct {
name string
input string
want int64
err error
}{
{name: "valid", input: "42", want: 42},
{name: "invalid", input: "no", err: strconv.ErrSyntax},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := strconv.ParseInt(tc.input, 10, 64)
if !errors.Is(err, tc.err) {
t.Fatalf("error = %v, want %v", err, tc.err)
}
if err == nil && got != tc.want {
t.Errorf("value = %d, want %d", got, tc.want)
}
})
}
}
Do not add guessed sleeps to make a flaky test pass. Also, an empty table or a fixture reader that finds no files can pass vacuously: assert required case data.
Verification boundary
Name checks actually executed and any required check that was unavailable. A race pass only covers executed paths. A compile pass is not wire parity. Do not promote parity status without a test that detects the claimed regression.
References
Original workflow and example informed by Go project documentation.
04 同仓库更多 Skills
spf13-go
Review Go library APIs, package boundaries, tests, iterators and standard-library choices. Load for broad design or idiom reviews after the repository-owned Go skills.
samber-golang-error-handling
Review Go error creation, wrapping, inspection and logging boundaries. Load when changing caller-visible failures after go-errors-and-context.
samber-golang-context
Design Go context propagation, cancellation, deadlines and request metadata. Load for operation-lifetime changes or context-related leaks after go-errors-and-context.
jetbrains-go-modern-guidelines
Choose version-compatible modern Go syntax and standard-library APIs. Load when modernizing touched Go code after reading go.mod and build constraints.
go-release-modules
Review Go module dependencies, minimum versions, compatibility, semantic labels, release-action tags, and proxy discoverability. Use for release preparation, retractions, and major-version migration planning.
go-library-api-design
Design or review exported Go APIs, constructors, interfaces, generics, iteration, ownership, and compatibility. Use when adding or changing public Go library surface.