Source profileQuality 93/100Review permissions

omarluq/librecode/.librecode/skills/golang-testing/SKILL.md

golang-testing

Provides a comprehensive guide for writing production-ready Golang tests. Covers table-driven tests, test suites with testify, mocks, unit tests, integration tests, benchmarks, code coverage, parallel tests, fuzzing, fixtures, goroutine leak detection with goleak, snapshot testing, memory leaks, CI with GitHub Actions, and idiomatic naming conventions. Use this whenever writing tests, asking about testing patterns or setting up CI for Go projects. Essential for ANY test-related conversation in G

Source repository stars
29
Declared platforms
1
Static risk flags
1
Last source update
2026-08-25
Source checked
2026-08-25

Decision brief

What it does: where it fits

This skill guides the creation of production-ready tests for Go applications. Follow these principles to write maintainable, fast, and reliable tests.

Best for

    Not for

    • Tasks that require unconfirmed production actions or broad system permissions.
    • Environments where the pinned source and install steps cannot be inspected.

    Compatibility matrix

    Platform support, with evidence labels

    PlatformStatusEvidenceWhat to check
    CodexNot declaredNo explicit evidencePortability before use
    Claude CodeDeclaredSource recordInstall path and trigger
    CursorNot declaredNo explicit evidencePortability before use
    Gemini CLINot declaredNo explicit evidencePortability before use
    Open the compatibility checker

    Installation

    Inspect first. Install second.

    The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

    Source-detected install commandSource
    npx skills add https://github.com/omarluq/librecode --skill ".librecode/skills/golang-testing"
    Safe inspection promptEditorial

    Inspect the Agent Skill "golang-testing" from https://github.com/omarluq/librecode/blob/55976d67b4363001b349a5adb9f9b87b27d0bfcd/.librecode/skills/golang-testing/SKILL.md at commit 55976d67b4363001b349a5adb9f9b87b27d0bfcd. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

    Workflow

    What the source asks the agent to do

    1. 01

      Best Practices Summary

      1. Table-driven tests MUST use named subtests -- every test case needs a name field passed to t.Run 2. Integration tests MUST use build tags (//go:build integration) to separate from unit tests 3. Tests MUST NOT depend on execution order -- each test MUST be independently runnab…

      Table-driven tests MUST use named subtests -- every test case needs a name field passed to t.RunIntegration tests MUST use build tags (//go:build integration) to separate from unit testsTests MUST NOT depend on execution order -- each test MUST be independently runnable
    2. 02

      Test Structure and Organization

      Review the “Test Structure and Organization” section in the pinned source before continuing.

      Review and apply the “Test Structure and Organization” source section.
    3. 03

      File Conventions

      Review the “File Conventions” section in the pinned source before continuing.

      Review and apply the “File Conventions” source section.
    4. 04

      Naming Conventions

      Review the “Naming Conventions” section in the pinned source before continuing.

      Review and apply the “Naming Conventions” source section.
    5. 05

      Table-Driven Tests

      Table-driven tests are the idiomatic Go way to test multiple scenarios. Always name each test case.

      Table-driven tests are the idiomatic Go way to test multiple scenarios. Always name each test case.

    Permission review

    Static risk signals and limitations

    Runs scripts

    medium · line 302

    The documentation asks the agent to run terminal commands or scripts.

    go test -coverprofile=coverage.out ./...

    Runs scripts

    medium · line 305

    The documentation asks the agent to run terminal commands or scripts.

    go tool cover -html=coverage.out

    Evidence record

    Why each signal appears

    EvidenceSourceComputedTestedEditorial
    SignalValueEvidence typeMeaning
    Quality score93/100ComputedDocumentation, specificity, maintenance, and trust rules
    Repository stars29SourceRepository attention, not individual Skill quality
    Compatibility1 platformsSourceDeclared in the catalog source record
    Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

    Pinned source

    Provenance and original SKILL.md

    Repository
    omarluq/librecode
    Skill path
    .librecode/skills/golang-testing/SKILL.md
    Commit
    55976d67b4363001b349a5adb9f9b87b27d0bfcd
    License
    MIT
    Collected
    2026-08-25
    Default branch
    main
    View the original SKILL.md

    Persona: You are a Go engineer who treats tests as executable specifications. You write tests to constrain behavior, not to hit coverage targets.

    Thinking mode: Use ultrathink for test strategy design and failure analysis. Shallow reasoning misses edge cases and produces brittle tests that pass today but break tomorrow.

    Modes:

    • Write mode — generating new tests for existing or new code. Work sequentially through the code under test; use gotests to scaffold table-driven tests, then enrich with edge cases and error paths.
    • Review mode — reviewing a PR's test changes. Focus on the diff: check coverage of new behaviour, assertion quality, table-driven structure, and absence of flakiness patterns. Sequential.
    • Audit mode — auditing an existing test suite for gaps, flakiness, or bad patterns (order-dependent tests, missing t.Parallel(), implementation-detail coupling). Launch up to 3 parallel sub-agents split by concern: (1) unit test quality and coverage gaps, (2) integration test isolation and build tags, (3) goroutine leaks and race conditions.
    • Debug mode — a test is failing or flaky. Work sequentially: reproduce reliably, isolate the failing assertion, trace the root cause in production code or test setup.

    Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-testing skill takes precedence.

    Go Testing Best Practices

    This skill guides the creation of production-ready tests for Go applications. Follow these principles to write maintainable, fast, and reliable tests.

    Best Practices Summary

    1. Table-driven tests MUST use named subtests -- every test case needs a name field passed to t.Run
    2. Integration tests MUST use build tags (//go:build integration) to separate from unit tests
    3. Tests MUST NOT depend on execution order -- each test MUST be independently runnable
    4. Independent tests SHOULD use t.Parallel() when possible
    5. NEVER test implementation details -- test observable behavior and public API contracts
    6. Packages with goroutines SHOULD use goleak.VerifyTestMain in TestMain to detect goroutine leaks
    7. Use testify as helpers, not a replacement for standard library
    8. Mock interfaces, not concrete types
    9. Keep unit tests fast (< 1ms), use build tags for integration tests
    10. Run tests with race detection in CI
    11. Include examples as executable documentation

    Test Structure and Organization

    File Conventions

    // package_test.go - tests in same package (white-box, access unexported)
    package mypackage
    
    // mypackage_test.go - tests in test package (black-box, public API only)
    package mypackage_test
    

    Naming Conventions

    func TestAdd(t *testing.T) { ... }              // function test
    func TestMyStruct_MyMethod(t *testing.T) { ... } // method test
    func BenchmarkAdd(b *testing.B) { ... }          // benchmark
    func ExampleAdd() { ... }                        // example
    

    Table-Driven Tests

    Table-driven tests are the idiomatic Go way to test multiple scenarios. Always name each test case.

    func TestCalculatePrice(t *testing.T) {
        tests := []struct {
            name     string
            quantity int
            unitPrice float64
            expected  float64
        }{
            {
                name:      "single item",
                quantity:  1,
                unitPrice: 10.0,
                expected:  10.0,
            },
            {
                name:      "bulk discount - 100 items",
                quantity:  100,
                unitPrice: 10.0,
                expected:  900.0, // 10% discount
            },
            {
                name:      "zero quantity",
                quantity:  0,
                unitPrice: 10.0,
                expected:  0.0,
            },
        }
    
        for _, tt := range tests {
            t.Run(tt.name, func(t *testing.T) {
                got := CalculatePrice(tt.quantity, tt.unitPrice)
                if got != tt.expected {
                    t.Errorf("CalculatePrice(%d, %.2f) = %.2f, want %.2f",
                        tt.quantity, tt.unitPrice, got, tt.expected)
                }
            })
        }
    }
    

    Unit Tests

    Unit tests should be fast (< 1ms), isolated (no external dependencies), and deterministic.

    Testing HTTP Handlers

    Use httptest for handler tests with table-driven patterns. See HTTP Testing for examples with request/response bodies, query parameters, headers, and status code assertions.

    Goroutine Leak Detection with goleak

    Use go.uber.org/goleak to detect leaking goroutines, especially for concurrent code:

    import (
        "testing"
        "go.uber.org/goleak"
    )
    
    func TestMain(m *testing.M) {
        goleak.VerifyTestMain(m)
    }
    

    To exclude specific goroutine stacks (for known leaks or library goroutines):

    func TestMain(m *testing.M) {
        goleak.VerifyTestMain(m,
            goleak.IgnoreCurrent(),
        )
    }
    

    Or per-test:

    func TestWorkerPool(t *testing.T) {
        defer goleak.VerifyNone(t)
        // ... test code ...
    }
    

    testing/synctest for Deterministic Goroutine Testing

    Experimental: testing/synctest is not yet covered by Go's compatibility guarantee. Its API may change in future releases. For stable alternatives, use clockwork (see Mocking).

    testing/synctest (Go 1.24+) provides deterministic time for concurrent code testing. Time advances only when all goroutines are blocked, making ordering predictable.

    When to use synctest instead of real time:

    • Testing concurrent code with time-based operations (time.Sleep, time.After, time.Ticker)
    • When race conditions need to be reproducible
    • When tests are flaky due to timing issues
    import (
        "testing"
        "time"
        "testing/synctest"
        "github.com/stretchr/testify/assert"
    )
    
    func TestChannelTimeout(t *testing.T) {
        synctest.Run(func(t *testing.T) {
            is := assert.New(t)
    
            ch := make(chan int, 1)
            go func() {
                time.Sleep(50 * time.Millisecond)
                ch <- 42
            }()
    
            select {
            case v := <-ch:
                is.Equal(42, v)
            case <-time.After(100 * time.Millisecond):
                t.Fatal("timeout occurred")
            }
        })
    }
    

    Key differences in synctest:

    • time.Sleep advances synthetic time instantly when the goroutine blocks
    • time.After fires when synthetic time reaches the duration
    • All goroutines run to blocking points before time advances
    • Test execution is deterministic and repeatable

    Test Timeouts

    For tests that may hang, use a timeout helper that panics with caller location. See Helpers.

    Benchmarks

    → See samber/cc-skills-golang@golang-benchmark skill for advanced benchmarking: b.Loop() (Go 1.24+), benchstat, profiling from benchmarks, and CI regression detection.

    Write benchmarks to measure performance and detect regressions:

    func BenchmarkStringConcatenation(b *testing.B) {
        b.Run("plus-operator", func(b *testing.B) {
            for i := 0; i < b.N; i++ {
                result := "a" + "b" + "c"
                _ = result
            }
        })
    
        b.Run("strings.Builder", func(b *testing.B) {
            for i := 0; i < b.N; i++ {
                var builder strings.Builder
                builder.WriteString("a")
                builder.WriteString("b")
                builder.WriteString("c")
                _ = builder.String()
            }
        })
    }
    

    Benchmarks with different input sizes:

    func BenchmarkFibonacci(b *testing.B) {
        sizes := []int{10, 20, 30}
        for _, size := range sizes {
            b.Run(fmt.Sprintf("n=%d", size), func(b *testing.B) {
                b.ReportAllocs()
                for i := 0; i < b.N; i++ {
                    Fibonacci(size)
                }
            })
        }
    }
    

    Parallel Tests

    Use t.Parallel() to run tests concurrently:

    func TestParallelOperations(t *testing.T) {
        tests := []struct {
            name string
            data []byte
        }{
            {"small data", make([]byte, 1024)},
            {"medium data", make([]byte, 1024*1024)},
        }
    
        for _, tt := range tests {
            t.Run(tt.name, func(t *testing.T) {
                t.Parallel()
                is := assert.New(t)
    
                result := Process(tt.data)
                is.NotNil(result)
            })
        }
    }
    

    Fuzzing

    Use fuzzing to find edge cases and bugs:

    func FuzzReverse(f *testing.F) {
        f.Add("hello")
        f.Add("")
        f.Add("a")
    
        f.Fuzz(func(t *testing.T, input string) {
            reversed := Reverse(input)
            doubleReversed := Reverse(reversed)
            if input != doubleReversed {
                t.Errorf("Reverse(Reverse(%q)) = %q, want %q", input, doubleReversed, input)
            }
        })
    }
    

    Examples as Documentation

    Examples are executable documentation verified by go test:

    func ExampleCalculatePrice() {
        price := CalculatePrice(100, 10.0)
        fmt.Printf("Price: %.2f\n", price)
        // Output: Price: 900.00
    }
    
    func ExampleCalculatePrice_singleItem() {
        price := CalculatePrice(1, 25.50)
        fmt.Printf("Price: %.2f\n", price)
        // Output: Price: 25.50
    }
    

    Code Coverage

    # Generate coverage file
    go test -coverprofile=coverage.out ./...
    
    # View coverage in HTML
    go tool cover -html=coverage.out
    
    # Coverage by function
    go tool cover -func=coverage.out
    
    # Total coverage percentage
    go tool cover -func=coverage.out | grep total
    

    Integration Tests

    Use build tags to separate integration tests from unit tests:

    //go:build integration
    
    package mypackage
    
    func TestDatabaseIntegration(t *testing.T) {
        db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
        if err != nil {
            t.Fatal(err)
        }
        defer db.Close()
    
        // Test real database operations
    }
    

    Run integration tests separately:

    go test -tags=integration ./...
    

    For Docker Compose fixtures, SQL schemas, and integration test suites, see Integration Testing.

    Mocking

    Mock interfaces, not concrete types. Define interfaces where consumed, then create mock implementations.

    For mock patterns, test fixtures, and time mocking, see Mocking.

    Enforce with Linters

    Many test best practices are enforced automatically by linters: thelper, paralleltest, testifylint. See the samber/cc-skills-golang@golang-linter skill for configuration and usage.

    Cross-References

    • -> See samber/cc-skills-golang@golang-stretchr-testify skill for detailed testify API (assert, require, mock, suite)
    • -> See samber/cc-skills-golang@golang-database skill (testing.md) for database integration test patterns
    • -> See samber/cc-skills-golang@golang-concurrency skill for goroutine leak detection with goleak
    • -> See samber/cc-skills-golang@golang-continuous-integration skill for CI test configuration and GitHub Actions workflows
    • -> See samber/cc-skills-golang@golang-linter skill for testifylint and paralleltest configuration

    Quick Reference

    go test ./...                          # all tests
    go test -run TestName ./...            # specific test by exact name
    go test -run TestName/subtest ./...    # subtests within a test
    go test -run 'Test(Add|Sub)' ./...     # multiple tests (regexp OR)
    go test -run 'Test[A-Z]' ./...         # tests starting with capital letter
    go test -run 'TestUser.*' ./...        # tests matching prefix
    go test -run '.*Validation.*' ./...    # tests containing substring
    go test -run TestName/. ./...          # all subtests of TestName
    go test -run '/(unit|integration)' ./... # filter by subtest name
    go test -race ./...                    # race detection
    go test -cover ./...                   # coverage summary
    go test -bench=. -benchmem ./...       # benchmarks
    go test -fuzz=FuzzName ./...           # fuzzing
    go test -tags=integration ./...        # integration tests
    

    Frequently asked questions

    What to verify before installation and use

    What does the golang-testing source document cover?

    This skill guides the creation of production-ready tests for Go applications. Follow these principles to write maintainable, fast, and reliable tests.

    How do I install golang-testing?

    The source record exposes this install command: npx skills add https://github.com/omarluq/librecode --skill ".librecode/skills/golang-testing". Inspect the command and pinned source before running it.

    Which Agent platforms does the source record declare?

    The pinned source record declares support for: claude code.

    Which permission-related actions were detected?

    Static rules flagged exec-script in the source; the page lists the matching lines and excerpts.

    Alternatives

    Compare before choosing

    Computed 973,066

    samber/cc-skills-golang

    golang-testing

    Production-ready Golang tests — table-driven tests, testify suites and mocks, parallel tests, fuzzing, fixtures, goroutine leak detection with goleak, snapshot testing, code coverage, integration tests, idiomatic test naming. Use when writing or reviewing Go tests, choosing a testing approach, setting up Go test CI, or debugging flaky/slow tests. For testify-specific APIs see `samber/cc-skills-golang@golang-stretchr-testify`; for measurement methodology see `samber/cc-skills-golang@golang-benchm

    Computed 967

    aomi-labs/skills

    aomi-build

    Scaffold new Aomi apps and plugins from API docs, OpenAPI/Swagger specs, or SDK references. aomi-build generates production-ready Rust SDK crates (lib.rs, client.rs, tool.rs) with tool schemas, preambles, host-interop flows, and validation — turning a vendor's API surface into AI-agent-callable tools. It covers the current `aomi-build` OpenAPI pipeline (`gen-specs` → `gen-client` → `gen-tool` → curate → compile/test) as well as greenfield apps. Use when the user wants to scaffold a new Aomi app

    Computed 95203

    PramodDutta/qaskills

    API Test Suite Generator

    Automatically generate comprehensive API test suites from OpenAPI specifications covering CRUD operations, error handling, authentication, pagination, and edge cases

    Computed 9565

    brucesongs/kali-claw

    eu-ai-act-compliance-redteam

    EU AI Act (Regulation (EU) 2024/1689) compliance-focused red team testing for high-risk AI systems — Article 9 adversarial testing, Annex III classification, Annex IV technical documentation, conformity assessment, and Notified Body audit preparation. Enforceable since 2 August 2026 with fines up to €35M or 7% global turnover.