testing
БесплатноБез исполняемых скриптовНе проверенTesting philosophy and practices. This skill should be used when writing tests, designing test strategies, or reviewing test code. Use proactively when…
Об этом скилле
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:
- Red: Write a failing test for the next piece of functionality
- Green: Write the minimum code necessary to make the test pass
- 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:
- Arrange: Set up the preconditions
- Act: Execute the behavior being tested
- 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
Установить testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл testing?
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)
Как установить скилл testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic