Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

test-data-patterns

БесплатноБез исполняемых скриптовНе проверен

Use for any question or task about how tests build their data, including Object Mother vs Test Data Builder, long constructor calls repeated across tests, and…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

test-data-patterns

Overview

A catalog of six ways to construct test data. Pick the pattern here, then configure the tool with faker-data or synthetic-data-toolkit.

How to use this catalog

  1. Inventory. List how the suite builds data today: grep for inline object literals, shared setUp / beforeAll state, factory files, snapshot files, and any production dump loaded into test databases.
  2. Pick. For each entity, choose a pattern from the Pattern-selection guide. One construction pattern per entity type; Builder over Factory is the only common mix.
  3. Check. Run the pattern's anti-pattern table against the existing code. Stop and fix any production data that is not anonymised before anything else (Pattern 6).
  4. Hand off. Configure the tool with the skill in Hand-off targets, then re-run the suite twice in random order (pytest --random-order with pytest-random-order, [jest --randomize][jcli]) to confirm no test depends on another's data.

Do not use this skill to:

  • Configure a specific tool - that's the per-language skill for that tool.
  • Generate negative / boundary / parameterized test data - that's negative-test-generator, boundary-value-generator, pairwise-test-case-generator.
  • Author an E2E seed fixture for the whole suite - that's seed-data-curator.

Pattern 1 - Test Data Builder

Canonical source: Nat Pryce and Steve Freeman, the Test Data Builder pattern (see References).

Definition: A Test Data Builder is a class with chainable methods (.withName("Alice").withOrgId(42).build()) that constructs domain objects step-by-step. Every field has a sensible default; the test overrides only the fields it cares about.

Concrete implementation (TypeScript, runnable):

type User = { role: string; org: { plan: string } };

class UserBuilder {
  private user: User = { role: "standard", org: { plan: "free" } };
  withRole(role: string) { this.user.role = role; return this; }
  withOrg(org: User["org"]) { this.user.org = org; return this; }
  build(): User { return { ...this.user }; }
}
const aUser = () => new UserBuilder();

// Test overrides only the fields it cares about:
const admin = aUser().withRole("admin").build();

When to use Test Data Builder

  • Domain objects have 5+ fields and most tests only care about 1-2.
  • The team values explicit "what this test cares about" in the test body.
  • The language has chainable / fluent API support (most modern languages).

Anti-patterns

Anti-pattern Why it fails
Builders with .set<Field>(value) for every field (no defaults) Loses the pattern's benefit; every test specifies every field
Builders that mutate the object in place rather than returning a new one Test cross-coupling: builders shared between tests leak state
Builders that perform side effects (build() writes to DB) Mixes two concerns; the test cannot tell whether it's constructing or persisting
Builders for objects with 2 fields Overhead exceeds benefit; use a struct literal

Pattern 2 - Factory (with traits and associations)

Canonical source: Thoughtbot's factory_bot (Ruby) is the cross-language reference implementation; the pattern adapts the Gang of Four Factory Method for test data.

Definition: A Factory is a registered, named template for creating an object. Traits are named modifiers (:admin, :disabled, :premium) that compose with the base template. Associations express relationships (user.org, org.plan).

Example (Ruby FactoryBot, the reference implementation):

factory :user do
  name { Faker::Name.name }
  email { Faker::Internet.email }

  trait :admin do
    role { :admin }
  end

  trait :with_org do
    association :org, factory: :org
  end
end

# Test usage:
admin_user = create(:user, :admin, :with_org)

The same factory in Python ([factory_boy reference][fb]): traits live in class Params and switch on with one boolean; SubFactory builds the association with the caller's strategy, so build() saves nothing.

import factory

class UserFactory(factory.Factory):
    class Meta:
        model = User

    name = factory.Faker("name")
    email = factory.Faker("email")
    role = "standard"
    org = None

    class Params:
        admin = factory.Trait(role="admin")
        with_org = factory.Trait(org=factory.SubFactory(OrgFactory))

admin_user = UserFactory.build(admin=True, with_org=True)  # not persisted

Cross-language equivalents (canonical per-language tool; URLs in References):

  • Ruby: factory_bot - the origin.
  • Python: factory_boy - direct port.
  • JS/TS: fishery, @faker-js/faker (lower-level).
  • .NET: Bogus - Faker-style with factory affordances.
  • Java: data-faker + handwritten factory or test-data-builder-style libraries.

When to use Factory

  • The project uses a database (factories handle FK r
Полный SKILL.md на GitHub

Установить test-data-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.json

FAQ

Что делает скилл test-data-patterns?

Use for any question or task about how tests build their data, including Object Mother vs Test Data Builder, long constructor calls repeated across tests, and shared fixtures that one test changes and ten others break on. Explains Test Data Builder, Factory, Object Mother, fixture composition, snapshots and production-data anonymization, and when each fits, before picking a tool.

Как установить скилл test-data-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл test-data-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить test-data-patterns с