Skill Featured

Generate Comprehensive Go Test Suites

An expert Go test generator that writes table-driven, GoMock-backed test suites - unit, HTTP handler, benchmark, and database tests.

Works with githubtestifygomock

87
Spark score
out of 100
Status Verified Official
Updated 11 days ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Automate the creation of robust and maintainable Go test suites. This asset generates unit, integration, and benchmark tests, incorporating best practices for Go's testing ecosystem.

Outcomes

What it gets done

01

Generate table-driven tests with Arrange-Act-Assert pattern.

02

Create mocks for dependencies using GoMock.

03

Write HTTP handler tests with httptest.

04

Produce benchmark tests for performance analysis.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-go-test-generator | bash

Overview

Go Test Generator

An expert Go test generator that writes idiomatic, table-driven test suites - unit, mock-based, HTTP handler, benchmark, and database integration tests - using the standard testing package, Testify, and GoMock. Use it to scaffold or extend a Go project's tests, especially when you want GoMock-based mocks and Go-idiomatic structure (table-driven, t.Helper(), Arrange-Act-Assert) rather than ad hoc test code.

What it does

Generates comprehensive Go test suites built on Go idioms: table-driven tests for multiple cases, the TestXxx naming convention with descriptive names, an Arrange-Act-Assert structure, t.Helper() for helper functions, proper error handling and assertions, and explicit coverage of positive, negative, edge, and boundary cases. It produces ready-to-use test code across several categories: standard table-driven unit tests; mock-based tests using GoMock (gomock.NewController, //go:generate mockgen) against interface-defined dependencies such as a Repository interface with GetUser/SaveUser; HTTP handler tests that mock a service layer via httptest and assert on status code and JSON response body; benchmark tests including parallel variants with b.ResetTimer() and b.ReportAllocs(); database integration tests gated by testing.Short() with explicit setup/teardown helpers; and reusable test utilities such as factory functions for building test fixtures and dedicated equality-assertion helpers.

When to use - and when NOT to

Use it to scaffold or extend a Go project's test suite - unit tests for a function or package, HTTP handler tests, database integration tests, or benchmarks. It also reaches for patterns beyond basic table-driven cases when the code under test calls for them: property-based testing where appropriate, and context-cancellation testing for concurrent code.

Inputs and outputs

Input is the Go code to be tested - a function, HTTP handler, repository, or service. Output is idiomatic Go test source: table-driven _test.go files, go:generate mockgen directives plus the resulting mock-based test, benchmark functions including BenchmarkFunctionNameParallel-style parallel variants, integration tests with database setup/cleanup helpers, and standalone test-utility functions such as createTestUser and assertUserEqual.

Integrations

Built around Go's standard library testing package plus the wider Go testing ecosystem: Testify (assert/require), GoMock (gomock.NewController, mockgen), httptest for HTTP handler tests, testify/suite for suites with setup/teardown, golden-file testing, go:build tags for separating integration tests, and the -race flag for concurrency testing.

Who it's for

For Go developers and teams who want consistent, idiomatic test coverage without hand-writing every table-driven case, mock, or benchmark. It also encodes coverage and quality guidelines - targeting 80%+ coverage on critical paths, testing all public interfaces, error-path testing, testing concurrent access patterns, validating input sanitization, testing configuration edge cases, and including integration tests for external dependencies - so generated suites match a stated quality bar rather than an arbitrary one.

func TestFunctionName(t *testing.T) {
    tests := []struct {
        name     string
        input    InputType
        expected ExpectedType
        wantErr  bool
    }{
        {
            name:     "valid input",
            input:    validInput,
            expected: expectedOutput,
            wantErr:  false,
        },
        {
            name:     "invalid input",
            input:    invalidInput,
            expected: zeroValue,
            wantErr:  true,
        },
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            result, err := FunctionName(tt.input)
            
            if tt.wantErr {
                assert.Error(t, err)
                return
            }
            
            assert.NoError(t, err)
            assert.Equal(t, tt.expected, result)
        })
    }
}

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.