test-isolation

Isolate tests with per-test setup and teardown to prevent shared state.

13|2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/yanko-belov/code-craft --skill test-isolation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-isolation
Source: https://github.com/yanko-belov/code-craft/tree/main/skills/test-isolation
Command: npx skills add https://github.com/yanko-belov/code-craft --skill test-isolation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill ensures tests are fully isolated, with no shared state or dependencies between tests, enabling reliable, repeatable, and parallel-friendly test execution.

Core Features & Use Cases

  • Fresh instance per test to guarantee isolation.
  • Patterns for setup and teardown to prevent cross-test contamination.
  • Guidance for avoiding beforeAll and shared mutable state, with examples of proper test structure and isolation techniques.

Quick Start

Create a new test that uses beforeEach to initialize fresh service or repository, and afterEach to clean up resources. Avoid using beforeAll; ensure tests do not rely on other tests' state.

Frequently Asked Questions about test-isolation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do my unit tests fail when running in parallel but pass individually?

Unit tests fail in parallel when they share mutable state or rely on execution order. Isolating tests with fresh instances per test case prevents cross-test contamination and ensures deterministic outcomes regardless of run order.

How do I isolate tests to prevent shared state across test cases?

Isolate tests by using beforeEach to initialize fresh services or repositories and afterEach to clean up resources. This per-test setup and teardown pattern prevents cross-test contamination and discourages shared mutable global state.

Should I use beforeAll or beforeEach for deterministic test setup?

Use beforeEach for deterministic test setup. beforeAll creates shared mutable state across test cases, which breaks isolation. Initializing fresh instances in beforeEach ensures every test runs independently and produces repeatable results.

What is test isolation and when do I need it for integration tests?

Test isolation ensures no shared state or dependencies exist between test cases. You need it for integration tests and unit test suites that must run in parallel or in any order, guaranteeing reliable and repeatable execution.

What are the limitations of using global state in test suites?

Global state breaks test isolation by creating hidden dependencies between test cases. This causes non-deterministic failures when tests run in different orders or in parallel, making test suites unreliable and difficult to debug.