shredbx logo
shredbx shredbx shredbx shredbx Personal
  • Home
  • Lab
  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
AClaude
  • Home
  • Lab
  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
Andrei Solovev
Knowledge
Search knowledge... ⌘K
Knowledge · Guidelines · go

Fixture Management

How to create, organize, and consume test fixtures in Go packages

Andrei Solovev

Metadata

go go recommended

Procedures

Showing 3 of 6

  1. 1 Create testdata/ directory in the target package
    Go toolchain ignores testdata/ directories (language-level convention). Place fixture files here for automatic exclusion from builds.
    mkdir -p pkg/server/testdata
  2. 2 Create fixture YAML files following naming convention
    Name: {entity}_{scenario}.yml. Each file has type: fixture header, entity, scenario, tags, input, and expected sections.
    # pkg/server/testdata/server_valid_creation.yml
    type: fixture
    entity: server
    scenario: valid-creation
    tags: [happy-path, api, unit]
    input:
      name: "test-vps-01"
      host: "10.0.0.1"
    expected:
      status: 201
      body:
        name: "test-vps-01"
  3. 3 Create a fixture loader in testutil/
    Build a helper that reads YAML fixtures and returns typed structs. Use t.Helper() for clean test output.
    // pkg/server/testutil/fixtures.go
    func LoadFixture(t *testing.T, name string) *Fixture {
        t.Helper()
        data, err := os.ReadFile(filepath.Join("testdata", name+".yml"))
        require.NoError(t, err)
        var f Fixture
        require.NoError(t, yaml.Unmarshal(data, &f))
        return &f
    }

Tools

  • go test
  • go test -update
  • gopkg.in/yaml.v3
shredbx logo shredbx shredbx shredbx shredbx Andrei Solovev

Solution Architect & Lead Software Engineer

ExperiencePortfolioResearch & ExperimentsEducationCertificationSkills
GitHub ↗LinkedIn ↗Email ↗
AVAILABLE FOR NEW PROJECTS
// MY LATEST BEATS
Hobby & Interests

Lab

  • The Lab
  • Framework
  • Components
  • Packages
  • Games
  • Process (SDLC)
  • Knowledge
  • Blog

Andrei

  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
  • Lifestyle

Team

  • Team
  • Andrei
  • Claude

Legal

  • Privacy
  • Terms
  • Cookies
© 2026 shredbx.com. All rights reserved. — Andrei Solovev |