Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

testing

FreeNo executable scriptsNot checked

Testing philosophy and practices. This skill should be used when writing tests, designing test strategies, or reviewing test code. Use proactively when…

boochby booch★ 18 GitHub stars23 installs in other catalogs

About this skill

Testing

This skill provides guidance on testing philosophy and practices, emphasizing tests as specifications and API design through TDD.

Core Philosophy

Tests as Executable Specifications

Tests are not just verification tools — they are executable specifications that document how the system should behave. A well-written test suite serves as living documentation.

Tests as API Consumers

Tests are the first users of your code's APIs. This is why TDD is valuable: you design the API by thinking about the consumer first, before thinking about implementation.

When writing tests:

  • Consider what interface would be most convenient for the caller
  • Let the test drive the API design
  • If the test is awkward to write, the API is awkward to use

Test-Driven Development (TDD)

Red-Green-Refactor

The TDD cycle consists of three phases:

  1. Red: Write a failing test for the next piece of functionality
  2. Green: Write the minimum code necessary to make the test pass
  3. Refactor: Improve the code while keeping tests green

Each cycle should be short — ideally minutes, not hours. Small steps reduce risk and provide frequent feedback.

The Value of TDD

  • Forces thinking about the API before implementation
  • Produces code with high test coverage by default
  • Encourages simpler designs (testable code tends to be well-designed)
  • Provides immediate feedback on whether code works
  • Creates executable documentation of intended behavior

Flexible TDD

Strict TDD (one test at a time, red-green-refactor) is the ideal for learning and for complex logic. However, flexibility is acceptable:

Writing all tests first is appropriate when:

  • Tests need human review/approval before implementation
  • The behavior is well-understood and stable
  • Documenting a specification before implementing

Writing tests after is acceptable when:

  • Exploring or prototyping (but add tests before committing)
  • The design is genuinely uncertain
  • Spiking to learn about a problem

The goal is well-tested code with tests that serve as specifications. The path matters less than the destination, but TDD often produces better results.

Speed Matters

Tests should be fast. Slow tests discourage running them frequently, which defeats their purpose.

  • Target sub-second feedback for unit tests
  • Keep the full suite under a few minutes when possible
  • Identify and isolate slow tests

Database Access

Avoid hitting the database in tests except when:

  • Testing database-specific functionality (queries, constraints, transactions)
  • Integration tests that specifically verify database behavior

Do not hit the database just to:

  • Populate models or data structures
  • Create test fixtures when in-memory objects would suffice
  • Test business logic that happens to use database-backed models

Use factories or builders that create in-memory objects when database persistence isn't the thing being tested.

Test Structure

One Thing Per Test

Each test should verify one behavior. This doesn't always mean one assertion — sometimes verifying one behavior requires multiple assertions, especially when tests are slow. But the test should have a single reason to fail.

AAA Pattern

Structure tests using Arrange-Act-Assert:

  1. Arrange: Set up the preconditions
  2. Act: Execute the behavior being tested
  3. Assert: Verify the expected outcome

Keep each section clearly delineated. If any section is complex, consider extracting helper methods.

Given-When-Then

The BDD mindset aligns with AAA:

  • Given (Arrange): The initial context
  • When (Act): The event or action
  • Then (Assert): The expected outcome

This framing helps focus on behavior from the user's perspective.

Mocking and Test Doubles

Prefer Real Objects

Avoid mocking when possible. Build small, simple components with immutable data to reduce the need for mocks.

When Mocking is Necessary

If mocking is unavoidable:

  • Mock roles, not objects — mock interfaces/behaviors, not concrete implementations
  • Prefer fakes over mocks — fakes (simplified implementations) are often clearer than mock expectations
  • Keep mock setups simple; complex mocking often signals design problems

Signs of Excessive Mocking

  • Tests that are mostly mock setup
  • Mocks returning mocks
  • Tests that break when implementation details change
  • Difficulty understanding what's actually being tested

Consider these as signals to refactor the production code.

Custom Matchers

Use custom matchers (RSpec matchers, Jest matchers, etc.) to make assertions readable and intention-revealing.

Good:

expect(order).to be_fulfilled
expect(user).to have_permission(:admin)

Less clear:

expect(order.status).to eq("fulfilled")
expect(user.permissions).to include("admin")

Custom matchers:

  • Make tests read like specifications
  • Provide better failure messages
  • Encapsulate complex assertions
  • Can be reused acros
Full SKILL.md on GitHub

Install testing in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the testing skill do?

Testing philosophy and practices. This skill should be used when writing tests, designing test strategies, or reviewing test code. Use proactively when discussing TDD, red-green-refactor, test doubles, mocks, stubs, fakes, RSpec, Jest, pytest, unit tests, integration tests, test coverage, or test-first development. (user)

How do I install the testing skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the testing skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare testing with