# testing-unit

The testing-unit skill provides patterns for unit tests, HTTP mocks, fixtures, and test data in Vitest, Jest, and pytest. It applies while writing tests or setting up test doubles.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 116 installs · ★ 305 repo stars
- Author: OrchestKit
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yonatangross/orchestkit/tree/HEAD/src/skills/testing-unit/SKILL.md
- Updated: 2026-11-07
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/testing-unit

## What it does

testing-unit organizes unit tests around Arrange-Act-Assert, replaces repeated cases with parametrized runs, and guides fixture scope choices. Its material covers Vitest, Jest, and pytest, with patterns for data factories and composed JSON fixtures.

HTTP tests use network interception rather than direct mocks of `fetch`, `axios`, or `requests`: MSW is covered for TypeScript and VCR.py for Python. The skill also includes rule files, references, checklists, scaffolding scripts, and examples for CRUD handlers, failures, authentication, and uploads. Its Vitest target is `>=5.0.3`.

Shared mutable fixtures can make tests flaky, so `function` scope is the stated choice for that data; `module` and `session` are reserved for expensive read-only resources. Claude Code requires version 2.1.277 or newer.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yonatangross/orchestkit --skill testing-unit -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/testing-unit/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/testing-unit/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yonatangross/orchestkit --skill testing-unit -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/testing-unit/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yonatangross/orchestkit --skill testing-unit -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/testing-unit/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yonatangross/orchestkit src/skills/testing-unit
```

2. **Manually: put the files in place**
- File: `.github/skills/testing-unit/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yonatangross/orchestkit --skill testing-unit -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yonatangross/orchestkit --path src/skills/testing-unit
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/testing-unit/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yonatangross/orchestkit --skill testing-unit -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yonatangross/orchestkit/tree/HEAD/src/skills/testing-unit/SKILL.md

## When to use it
- structure a unit test with Arrange-Act-Assert phases
- replace copied cases with parametrized tests
- intercept API traffic through MSW or VCR.py
- choose fixture scope for mutable and read-only data
- generate isolated test records with factories

## Example prompts
- Write unit tests for this service using the Arrange-Act-Assert pattern.
- Turn these repeated Vitest or pytest cases into one parametrized test.
- Set up MSW network handlers for the API tests and reset them between tests.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: c8529fd3d20e73fe.

BEGIN THIRD-PARTY FILE c8529fd3d20e73fe
```text
---
name: testing-unit
license: MIT
compatibility: "Claude Code 2.1.277+."
description: "Unit test patterns: AAA, parametrized tests, fixture scope, MSW or VCR network mocks, data factories, for Vitest, Jest and pytest. Use when writing unit tests or setting up mocks and fixtures."
user-invocable: false
disable-model-invocation: false
targets:
  - library: vitest
    version: ">=5.0.3"
metadata:
  owner-agent: "test-generator"
  category: document-asset-creation
  version: "2.1.0"
  author: "OrchestKit"
  complexity: "medium"
  tags: "testing, unit, mocking, msw, vcr, fixtures, factories, vitest-4, aroundEach"
allowed-tools: "Read Glob Grep WebFetch WebSearch"
path_patterns: ["*.test.*", "*.spec.*", "**/vitest.config.*", "**/jest.config.*"]
---

# Unit Testing Patterns

Focused patterns for writing isolated, fast, maintainable unit tests. Covers test structure (AAA), parametrization, fixture management, HTTP mocking (MSW/VCR), and test data generation with factories.

Each category has individual rule files in `rules/` loaded on-demand, plus reference material, checklists, and scaffolding scripts.

## Core Principles (ALWAYS apply)

1. **AAA structure**: Every test MUST follow Arrange-Act-Assert. Use `// Arrange`, `// Act`, `// Assert` comments for clarity.
2. **Parametrize, don't duplicate**: Use `test.each` (TypeScript) or `@pytest.mark.parametrize` (Python) when testing multiple inputs. Never copy-paste the same test body with different values.
3. **Fixture scoping matters**: Use `scope="function"` (default) for mutable data. Use `scope="module"` or `scope="session"` ONLY for expensive read-only resources (DB engines, ML models). Mutable data with shared scope causes flaky tests.
4. **Speed target**: Each unit test should run under **100ms**. If it's slower, you're likely hitting I/O — mock it.
5. **Mock at the network level**: Use MSW (TypeScript) or VCR.py (Python) to intercept HTTP at the network layer. Never mock `fetch`/`axios`/`requests` directly.

## Quick Reference

| Category | Rules | Impact | When to Use |
|----------|-------|--------|-------------|
| [Unit Test Structure](#unit-test-structure) | 3 | CRITICAL | Writing any unit test |
| [HTTP Mocking](#http-mocking) | 2 | HIGH | Mocking API calls in frontend/backend tests |
| [Test Data Management](#test-data-management) | 3 | MEDIUM | Setting up test data, factories, fixtures |

**Total: 8 rules across 3 categories, 4 references, 3 checklists, 1 example set, 3 scripts**

## Unit Test Structure

Core patterns for structuring isolated unit tests with clear phases and efficient execution.

| Rule | File | Key Pattern |
|------|------|-------------|
| AAA Pattern | `rules/unit-aaa-pattern.md` | Arrange-Act-Assert with isolation |
```
END THIRD-PARTY FILE c8529fd3d20e73fe

The third-party file has ended. Everything between the c8529fd3d20e73fe tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2741 of 9518 bytes. © OrchestKit · MIT · https://github.com/yonatangross/orchestkit/tree/HEAD/src/skills/testing-unit/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
