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★ 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
- Inventory. List how the suite builds data today: grep for inline
object literals, shared
setUp/beforeAllstate, factory files, snapshot files, and any production dump loaded into test databases. - 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.
- 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).
- Hand off. Configure the tool with the skill in
Hand-off targets, then re-run the suite twice in
random order (
pytest --random-orderwith 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
Установить test-data-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic