test-patterns

A guide to common ways of structuring software tests, such as Arrange-Act-Assert, test fixtures, parameterized tests, spies, and test doubles. These patterns describe how to prepare a test, run the code, and check the result clearly.

In plain words
What is it for?
Use it when writing or improving unit tests, integration tests, end-to-end tests, feature specifications, repeated test cases, or tests with external dependencies.
Why use it?
It helps make tests easier to read, maintain, and trust as setup becomes more complex. It also maps patterns to unit, integration, end-to-end, and behaviour-focused tests.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/rohitg00/skillkit/test-patterns
Any agent
npx skills add rohitg00/skillkit --skill test-patterns
Clone the repo
git clone --depth 1 https://github.com/rohitg00/skillkit

Made for: Claude Code, Codex.

Per session 138 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,668 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00138 $0.01668
Opus 5 $0.00069 $0.00834
Sonnet 5 $0.00028 $0.00334
Haiku 4.5 $0.00014 $0.00167

Measured 2d ago against content hash b47d6eaa1420, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/core/src/methodology/packs/testing/test-patterns/SKILL.md · 269 lines

How it starts

The opening of the file, as written. The whole thing — 269 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Test Patterns

You are applying proven testing patterns to write maintainable, reliable tests. These patterns help ensure tests are readable, focused, and trustworthy.

Pattern Selection Guide

Use this to choose the right pattern for your situation:

  • Structuring a single test? → Arrange-Act-Assert (AAA) or Given-When-Then
  • Writing behavior/feature specs? → Given-When-Then (BDD style)
  • Repeating test setup data? → Test Data Builders
  • Many variations of complex objects? → Object Mother
  • Testing same logic with many inputs? → Parameterized Tests
  • Shared setup/teardown across tests? → Test Fixtures
  • Verifying a dependency was called? → Spy
  • Replacing an external dependency? → Test Doubles (Stub / Mock / Fake)

Pattern Combination Workflows

Patterns rarely stand alone — here's how to combine them for common scenarios:

Unit tests (isolated logic): Fixtures for setup → AAA structure → Stubs/Mocks for dependencies → Parameterized Tests for multiple input cases

Integration tests (service + external dependencies): Fixtures for setup → AAA structure → Fakes for external services (e.g. in-memory DB) → Spies to verify interaction points

BDD / feature specs: Given-When-Then → Object Mother or Test Data Builders for scenario data → Fakes for infrastructure

High-variation logic (validators, calculators, formatters): Parameterized Tests → Test Data Builders to construct each case → AAA structure within each case


Core Pattern: Arrange-Act-Assert (AAA)

Structure every test with three distinct phases:

// Arrange - Set up test data and dependencies
const user = createTestUser({ role: 'admin' });
const service = new UserService(mockRepository);

// Act - Execute the code under test
const result = await service.updateRole(user.id, 'member');

// Assert - Verify the expected outcome
expect(result.role).toBe('member');
expect(mockRepository.save).toHaveBeenCalledWith(user);

Guidelines:

  • Keep sections visually separated (blank lines or comments)
  • Arrange should be minimal - only what's needed for this test
  • Act should be a single operation
  • Assert should verify one logical concept

Read the full file on GitHub · 269 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 269 lines · 138 tokens per session scan A b47d6eaa1420

Subscribe to this mod's changes

test-patterns is a skill published in the GitHub repository rohitg00/skillkit (1,477 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 138 tokens to every session and 1,668 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories