Command Palette

Search for a command to run...

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

test-isolation-patterns

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

Pure reference catalog of test-isolation and fixture-lifecycle patterns - the four-phase test pattern (Meszaros), fixture scope (per-test / per-describe /…

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

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

test-isolation-patterns

Overview

A test that fails sometimes for non-obvious reasons is non-deterministic. Per Martin Fowler - Eradicating Non-Determinism in Tests: "A test is non-deterministic when it passes sometimes and fails sometimes, without any noticeable change in the code, tests, or environment… Once you start ignoring a regression test failure, then that test is useless and you might as well throw it away." The dominant cause is broken isolation - one test affecting another, the environment leaking, fixtures sharing state. This catalog is the canonical reference for the isolation patterns that prevent it.

This skill is a pure reference - no execution steps. It is the catalog cited when auditing fixture coupling, retry/wait policy consistency, and CI integration health. It complements test-code-conventions §6 (which is the file-level rule against global-fixture hubs) with the cross-cutting architecture patterns. It also complements flake-pattern-reference, which catalogs flake symptoms; this skill catalogs the prevention patterns.

When to use

  • Designing a new framework - pick the fixture scope and isolation strategy.
  • Auditing an existing framework where flake-rate is rising (broken isolation drives the concurrency and test-order-dependency flake categories, together about a third of flakes per Luo et al. 2014).
  • Migrating from sequential to parallel execution - the parallel-safety patterns become load-bearing.
  • Refactoring fixture inheritance chains - apply the cleanup-discipline patterns.

How to use

  1. Frame each test in the four phases (Pattern 1). Be explicit about where Setup and Teardown live, because Phases 1 and 4 are where isolation breaks.
  2. Pick the tightest fixture scope that holds (Pattern 2). Default to per-test; escalate to per-describe or shared only when setup is measurably expensive and the group never mutates the fixture.
  3. Choose Fresh Fixture (Pattern 3), or a Persistent Fresh Fixture (transaction-rollback) when a fresh rebuild is measured too slow.
  4. For DB-backed or network-backed tests, pick an external-dependency strategy from references/database-store-isolation.md and references/network-service-isolation.md.
  5. Before enabling parallel execution, apply the parallel-safety patterns (Pattern 4): worker-scoped state, unique IDs, ephemeral paths, no global singletons.
  6. Wire teardown through the runner's afterEach by default (Pattern 5, cleanup discipline).
  7. Cross-check against the pattern-selection guide and the cross-cutting anti-patterns before sign-off.

Pattern 1 - The four-phase test pattern

Canonical source: Gerard Meszaros - xUnit Test Patterns: Refactoring Test Code (2007). Referenced in the Wikipedia entry on test fixture.

Every test has four phases:

Phase What
1. Setup Establish the pre-conditions / fixture
2. Exercise Interact with the System Under Test
3. Verify Determine whether the expected outcome was obtained
4. Teardown Return to a clean state

Phases 1 and 4 together are fixture management. Patterns 2 through 5 below cover how to do them safely; isolating external stores and services is covered in the deep references.

Pattern 2 - Fixture scope

The framework's test runner offers three or four scopes; the team picks the tightest scope that meets the constraint.

Scope Lifecycle Use when
Per-test (function-scoped) Setup before each test; teardown after each Default. Maximally isolated. Slowest. Always parallel-safe.
Per-describe (class / module-scoped) Setup before the first test in the group; teardown after the last Setup is expensive and the group of tests genuinely shares it (read-only)
Shared (session / worker-scoped) Setup once for the whole run; teardown at end Setup is unaffordable per-describe (e.g., spinning up a Docker stack) and the tests don't mutate it
Global (module-loading) Setup at module-import time; no teardown Anti-pattern in nearly all cases. Use only for truly immutable language-level fixtures (constants, configuration).

The single rule that prevents most flake: never share mutable fixtures across tests. If a fixture is mutated by any test, it must be per-test scoped.

Framework-specific scope syntax (illustrative; cite the per-framework skill for tool-specific details)

  • Jest / Vitest: beforeEach / beforeAll (per-describe by default within a describe block).
  • Playwright Test: test.beforeEach / test.beforeAll; test.use({}) for per-test config;
Полный SKILL.md на GitHub

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

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

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

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

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

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

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

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

.tessl-plugin/plugin.jsonevals/cleanup-after-failure/criteria.jsonevals/cleanup-after-failure/task.mdevals/factory-cleanup-ownership/criteria.jsonevals/factory-cleanup-ownership/task.mdevals/fixture-scope-strategy/criteria.jsonevals/fixture-scope-strategy/task.mdevals/parallel-readiness-audit/criteria.jsonevals/parallel-readiness-audit/task.mdevals/reset-not-recreate/criteria.jsonevals/reset-not-recreate/task.mdevals/rollback-strategy-limits/criteria.jsonevals/rollback-strategy-limits/task.mdevals/shared-bucket-leak/criteria.jsonevals/shared-bucket-leak/task.mdevals/shared-fixture-leaky-copy/criteria.jsonevals/shared-fixture-leaky-copy/task.mdevals/stale-module-reference/criteria.jsonevals/stale-module-reference/task.mdevals/worker-scope-collisions/criteria.jsonevals/worker-scope-collisions/task.mdreferences/database-store-isolation.mdreferences/network-service-isolation.md

FAQ

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

Pure reference catalog of test-isolation and fixture-lifecycle patterns - the four-phase test pattern (Meszaros), fixture scope (per-test / per-describe / shared / global), the Fresh-Fixture vs Shared-Fixture trade-off (Fowler), parallel-safety patterns, and cleanup discipline (afterEach / afterAll / tagged-cleanup), plus a pattern-selection guide and a worked leaking-state diagnosis. The database-isolation strategies (transaction-rollback / database-per-worker / template-database) and network / external-service stubbing live in references/. This is the architecture-tier reference, not a file-level fixture-coupling style rule. Use when designing fixture scope and isolation strategy, auditing fixture coupling or retry/wait policy, or moving a suite to parallel execution.

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

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

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

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

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

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