Skip to content
test-fixtures-go logo

Skill: test-fixtures-go

test-fixtures-go

Factory-go and gofakeit for Go test fixtures

baphled/dotopencode0installs1stars

SKILL.md

Full skill instructions

Skill: test-fixtures-go

What I do

I provide expertise in generating realistic test data for Go using factory-go patterns and gofakeit. I specialise in the functional options pattern for flexible, composable, and type-safe test fixtures.

When to use me

  • Creating realistic mock data for Go unit and integration tests.
  • Implementing the functional options pattern for object builders.
  • Need random but structured data (UUIDs, emails, names) in tests.
  • DRYing up test setup code across multiple Go spec files.

Core principles

  1. Realistic Data — Use gofakeit to generate data that mimics production values (valid emails, real-looking names).
  2. Functional Options — Prefer func(*Type) options for builders to keep the API clean and extensible.
  3. Type Safety — Ensure fixtures return the correct types and handle mandatory fields by default.
  4. Minimal Setup — Fixtures should return a valid object with zero arguments; override only what's needed.

Patterns & examples

Functional Options Pattern (Recommended)

type User struct {
    ID        string
    Email     string
    FirstName string
    Role      string
}

func NewUser(opts ...func(*User)) *User {
    user := &User{
        ID:        gofakeit.UUID(),
        Email:     gofakeit.Email(),
        FirstName: gofakeit.FirstName(),
        Role:      "user",
    }
    for _, opt := range opts {
        opt(user)
    }
    return user
}

// Options
func WithEmail(e string) func(*User) { return func(u *User) { u.Email = e } }
func WithRole(r string) func(*User)  { return func(u *User) { u.Role = r } }

// Usage
admin := NewUser(WithRole("admin"))

Integration with Ginkgo

var _ = Describe("UserService", func() {
    var user *User
    
    BeforeEach(func() {
        user = NewUser(WithRole("admin"))
    })
    
    It("grants admin privileges", func() {
        Expect(user.Role).To(Equal("admin"))
    })
})

Anti-patterns to avoid

  • ❌ Hardcoded Constants — Leads to "mystery guest" problems and fragile tests.
  • ❌ Manual Struct Literals — Duplicates setup logic and makes adding fields painful.
  • ❌ Over-complex Builders — If a fixture needs 10+ options, the struct likely needs refactoring.

KB Reference

~/​vaults/​baphled/​3. Resources/​Knowledge Base/​AI Development System/​Skills/​Testing-BDD/​Test Fixtures Go.md

Related skills

  • test-fixtures - Universal patterns for test data.
  • ginkgo-gomega - Go BDD testing framework.
  • golang - Core Go language idioms.

More skills from baphled

style-guide logo
baphled/dotopencode

style-guide

Style guide enforcement and documentation conventions

1 0
View
tdd-first logo
baphled/dotopencode

tdd-first

Enforce strict test-first discipline — no implementation code before a failing test exists

1 0
View
technical-debt logo
baphled/dotopencode

technical-debt

Identifying, documenting, and systematically managing technical debt to maintain codebase health

1 0
View
tdd-workflow logo
baphled/dotopencode

tdd-workflow

DEPRECATED - Use bdd-workflow instead

1 0
View
systems-thinker logo
baphled/dotopencode

systems-thinker

Understand complex systems, interconnections, and emergent behaviors

1 0
View
trade-off-analysis logo
baphled/dotopencode

trade-off-analysis

Systematically evaluate trade-offs when comparing alternatives

1 0
View
tool-usage-discipline logo
baphled/dotopencode

tool-usage-discipline

Use skills for domain knowledge, MCP tools over manual lookups

1 0
View
writing-style logo
baphled/dotopencode

writing-style

Personal writing voice and communication style conventions

1 0
View
token-cost-estimation logo
baphled/dotopencode

token-cost-estimation

Estimate and track token costs before work sessions - complexity, duration, resources

1 0
View
ux-design logo
baphled/dotopencode

ux-design

Intuitive user experiences in terminal applications - mental models, interaction patterns

1 0
View
skill-discovery logo
baphled/dotopencode

skill-discovery

Automatically discover/load local skills and suggest external skills based on task context

1 0
View
token-efficiency logo
baphled/dotopencode

token-efficiency

Maximise AI interaction value per token - techniques, patterns, integration with cost estimation

1 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View