Skip to content
test-fixtures logo

Skill: test-fixtures

test-fixtures

Test data factory patterns

baphled/dotopencode0installs1stars

SKILL.md

Full skill instructions

Skill: test-fixtures

What I do

I provide expertise in consistent, realistic test data through factory patterns. I replace manual construction of complex test objects with factories that provide sensible defaults while allowing precise overrides for specific test scenarios.

When to use me

  • Defining test data once and reusing it across entire test suites (DRY).
  • Need valid, realistic objects without cluttering tests with irrelevant setup details.
  • Isolating tests from changes in object internal structures (e.g. new mandatory fields).
  • Managing complex object graphs and relationships in tests.

Core principles

  1. DRY Test Data — Define test objects once, reuse everywhere.
  2. Realistic Defaults — Use faker libraries for realistic, but random, data out of the box.
  3. Explicit Customisation — Override only what matters for the specific test case.
  4. Independence — Ensure each test gets fresh, non-shared objects to avoid leaks.
  5. Type Safety — Factories should return correctly typed objects or valid database records.

Patterns & examples

Factory Functions (Universal Pattern)

// JavaScript/​TypeScript example
import { faker } from '@faker-js/​faker';

export function createUser(overrides = {}) {
  return {
    id: faker.string.uuid(),
    email: faker.internet.email(),
    firstName: faker.person.firstName(),
    role: 'user',
    createdAt: new Date(),
    ...overrides,
  };
}

// Usage in tests
const admin = createUser({ role: 'admin' });

Traits and States (Ruby/​FactoryBot)

FactoryBot.define do
  factory :user do
    email { Faker::Internet.email }
    trait :admin do
      role { 'admin' }
    end
    trait :with_posts do
      after(:create) { |u| create_list(:post, 3, author: u) }
    end
  end
end

# Usage
author = create(:user, :with_posts)

Anti-patterns to avoid

  • ❌ Hardcoded Constants — e.g. "[email protected]"; use random/​realistic data to avoid accidental collisions.
  • ❌ Manual Over-setup — Setting 10 fields in a test that only cares about one; use factory defaults.
  • ❌ Shared Mutable Fixtures — Sharing the same object instance between tests; leads to flaky tests.
  • ❌ Business Logic in Factories — Factories should only create data, not perform complex operations.

KB Reference

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

Related skills

  • test-fixtures-go - Go-specific factory-go/​gofakeit implementation.
  • bdd-workflow - Using fixtures effectively in the Red-Green-Refactor cycle.
  • clean-code - Applying DRY and Single Responsibility to test data.

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