Test Patterns logo

Test Patterns

CommunityPopular
rohitg00
test-patterns

Applies proven testing patterns — Arrange-Act-Assert (AAA), Given-When-Then, Test Data Builders, Object Mother, parameterized tests, fixtures, spies, and test doubles — to help write maintainable, reliable, and readable test suites. Use when the user asks about writing unit tests, integration tests, or end-to-end tests; structuring test cases or test suites; applying TDD or BDD practices; working with mocks, stubs, spies, or fakes; improving test coverage or reducing flakiness; or needs guidance on test organization, naming conventions, or assertions in frameworks like Jest, Vitest, pytest, or similar.

Overview

Publisherrohitg00
Repositoryskillkit
Skill nametest-patterns
Stars
1.5K
Forks
147
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by rohitg00 on GitHub. Read the source before you install it.

Installation

Install the Test Patterns AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/rohitg00/skillkit.git /tmp/skillkit
mkdir -p .claude/skills
cp -r /tmp/skillkit/packages/core/src/methodology/packs/testing/test-patterns .claude/skills/test-patterns
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Test Patterns in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Test Patterns on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Test Patterns is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

Pattern: Given-When-Then (BDD Style)

For behavior-focused tests:

describe('Shopping Cart', () => {
  describe('when adding an item', () => {
    it('should increase the item count', () => {
      // Given
      const cart = new Cart();

      // When
      cart.add({ id: '1', quantity: 2 });

      // Then
      expect(cart.itemCount).toBe(2);
    });
  });
});

Pattern: Test Data Builders

Create flexible test data without repetition:

// Builder function
function createTestOrder(overrides = {}) {
  return {
    id: 'order-123',
    status: 'pending',
    items: [],
    total: 0,
    ...overrides
  };
}

// Usage
const completedOrder = createTestOrder({ status: 'completed', total: 99.99 });
const emptyOrder = createTestOrder({ items: [] });

Pattern: Object Mother

Factory for complex test objects:

class TestUserFactory {
  static admin() {
    return new User({ role: 'admin', permissions: ALL_PERMISSIONS });
  }

  static guest() {
    return new User({ role: 'guest', permissions: [] });
  }

  static withSubscription(tier) {
    return new User({ subscription: { tier, active: true } });
  }
}

Pattern: Parameterized Tests

Test multiple cases efficiently:

describe('isValidEmail', () => {
  const validCases = [
    'user@example.com',
    'user.name@domain.co.uk',
    'user+tag@example.org'
  ];

  const invalidCases = [
    '',
    'not-an-email',
    '@no-local.com',
    'no-domain@'
  ];

  test.each(validCases)('should accept valid email: %s', (email) => {
    expect(isValidEmail(email)).toBe(true);
  });

  test.each(invalidCases)('should reject invalid email: %s', (email) => {
    expect(isValidEmail(email)).toBe(false);
  });
});

Pattern: Test Fixtures

Reusable test setup:

describe('OrderService', () => {
  let service;
  let mockPaymentGateway;
  let mockInventory;

  beforeEach(() => {
    mockPaymentGateway = createMockPaymentGateway();
    mockInventory = createMockInventory();
    service = new OrderService(mockPaymentGateway, mockInventory);
  });

  afterEach(() => {
    jest.clearAllMocks();
  });
});

Pattern: Spy on Dependencies

Verify interactions without implementation:

it('should send notification on order completion', async () => {
  const notifySpy = jest.spyOn(notificationService, 'send');

  await orderService.complete(orderId);

  expect(notifySpy).toHaveBeenCalledWith({
    type: 'order_completed',
    orderId: orderId
  });
});

Pattern: Test Doubles

Choose the right type:

TypeWhen to Use
StubNeed predictable, canned return values
MockNeed to assert a dependency was called correctly
SpyPartial mocking — observe calls on a real object
FakeNeed a working lightweight substitute (e.g. in-memory DB)

Pattern: Test Isolation

Ensure tests don't affect each other:

  1. Fresh instances - Create new objects in each test
  2. Reset mocks - Clear mock state between tests
  3. Clean up - Remove side effects (files, database rows)
  4. No shared mutable state - Avoid global variables

Naming Conventions

Test names should describe:

  • What is being tested
  • Under what conditions
  • What the expected outcome is

Good examples:

  • shouldReturnEmptyArrayWhenNoItemsExist
  • throwsErrorWhenUserNotAuthenticated
  • calculatesDiscountForPremiumMembers

Test Organization

src/
  services/
    UserService.ts
    UserService.test.ts    # Co-located tests

tests/
  integration/
    api.test.ts            # Integration tests
  e2e/
    checkout.spec.ts       # End-to-end tests

Verification Checklist

For each test:

  • Single responsibility (tests one thing)
  • Clear AAA or GWT structure
  • Descriptive name
  • Fast execution (< 100ms for unit tests)
  • Deterministic (no flakiness)
  • Independent (runs in any order)

Frequently asked questions

What does the Test Patterns AI skill do?

Applies proven testing patterns — Arrange-Act-Assert (AAA), Given-When-Then, Test Data Builders, Object Mother, parameterized tests, fixtures, spies, and test doubles — to help write maintainable, reliable, and readable test suites. Use when the user asks about writing unit tests, integration tests, or end-to-end tests; structuring test cases or test suites; applying TDD or BDD practices; working with mocks, stubs, spies, or fakes; improving test coverage or reducing flakiness; or needs guidance on test organization, naming conventions, or assertions in frameworks like Jest, Vitest, pytest,...

Why use Test Patterns on TypingMind?

Because you install it once and use it with any model. Test Patterns is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Test Patterns in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/rohitg00/skillkit/tree/main/packages/core/src/methodology/packs/testing/test-patterns. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Test Patterns?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Test Patterns?

As many as you like. As long as a model supports skills, you can use Test Patterns with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Test Patterns AI skill free?

Yes. It is published on GitHub by rohitg00 under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇