Write idiomatic Go tests, benchmarks, fuzz tests, and improve coverage.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "golang-testing" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/golang-testing/SKILL.md 2. Save it as ~/.claude/skills/golang-testing/SKILL.md 3. Reload skills and tell me it's ready
Write table-driven tests for this Go function using the testing package. Cover normal inputs, edge cases, and invalid scenarios:
func Add(a, b int) int {
return a + b
}An idiomatic Go _test.go example with a test case table and assertion logic.
Create Go benchmarks for the following code, compare performance across implementations, and explain how to run and interpret the benchmark results: [paste your Go code]
Runnable Benchmark functions, execution commands, and guidance for performance comparison.
I want to build a Go feature with TDD. First write failing tests from the requirements, then provide the minimal implementation, and finally suggest refactoring steps. Requirements: [paste feature requirements]
Tests, implementation, and refactoring suggestions organized in TDD order.
Comprehensive Go testing patterns for writing reliable, maintainable tests following TDD methodology.
RED → Write a failing test first
GREEN → Write minimal code to pass the test
REFACTOR → Improve code while keeping tests green
REPEAT → Continue with next requirement
// Step 1: Define the interface/signature
// calculator.go
package calculator
func Add(a, b int) int {
panic("not implemented") // Placeholder
}
// Step 2: Write failing test (RED)
// calculator_test.go
package calculator
import "testing"
func TestAdd(t *testing.T) {
got := Add(2, 3)
want := 5
if got != want {
t.Errorf("Add(2, 3) = %d; want %d", got, want)
}
}
// Step 3: Run test - verify FAIL
// $ go test
// --- FAIL: TestAdd (0.00s)
// panic: not implemented
// Step 4: Implement minimal code (GREEN)
func Add(a, b int) int {
return a + b
}
// Step 5: Run test - verify PASS
// $ go test
// PASS
// Step 6: Refactor if needed, verify tests still pass
The standard pattern for Go tests. Enables comprehensive coverage with minimal code.
func TestAdd(t *testing.T) {
tests := []struct {
name string
a, b int
expected int
}{
{"positive numbers", 2, 3, 5},
{"negative numbers", -1, -2, -3},
{"zero values", 0, 0, 0},
{"mixed signs", -1, 1, 0},
{"large numbers", 1000000, 2000000, 3000000},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Add(tt.a, tt.b)
if got != tt.expected {
t.Errorf("Add(%d, %d) = %d; want %d",
tt.a, tt.b, got, tt.expected)
}
})
}
}
func TestParseConfig(t *testing.T) {
tests := []struct {
name string
input string
want *Config
wantErr bool
}{
{
name: "valid config",
input: `{"host": "localhost", "port": 8080}`,
want: &Config{Host: "localhost", Port: 8080},
},
{
name: "invalid JSON",
input: `{invalid}`,
wantErr: true,
},
{
name: "empty input",
input: "",
wantErr: true,
},
{
name: "minimal config",
input: `{}`,
want: &Config{}, // Zero value config
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseConfig(tt.input)
if tt.wantErr {
if err == nil {
t.Error("expected error, got nil")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %+v; want %+v", got, tt.want)
}
})
}
}
func TestUser(t *testing.T) {
// Setup shared by all subtests
db := setupTestDB(t)
t.Run("Create", func(t *testing.T) {
user := &User{Name: "Alice"}
err := db.CreateUser(user)
if err != nil {
t.Fatalf("CreateUser failed: %v", err)
}
if user.ID == "" {
t.Error("expected user ID to be set")
}
})
t.Run("Get", func(t *testing.T) {
user, err := db.GetUser("alice-id")
if err != nil {
t.Fatalf("GetUser failed: %v", err)
}
…
Speed up complex tasks with parallel execution while preserving correctness.
Learn practical Kotlin Ktor server patterns for building and testing backend apps.
Extract shared principles from skills and turn them into maintainable rule files.
Coordinate behavior-preserving code refactors with tests, review, and gated commits.
Design compliant PHI and PII protection patterns for healthcare applications.
Run a pre-release verification loop for Quarkus builds, tests, scans, and reviews.
Learn idiomatic Go patterns and best practices for robust, maintainable applications.
Learn Rust testing patterns and TDD to improve code quality and reliability.
Build high-quality Kotlin tests with Kotest, MockK, coroutines, and coverage.
Build features, fix bugs, and refactor code with test-driven development.
Write, run, and improve Perl automated tests with coverage analysis.
Generate idiomatic, production-ready Go code and engineering best practices.