tdd
БесплатноБез исполняемых скриптовНе проверенTest-Driven Development methodology. Use this skill when writing tests, when the user asks for TDD, when implementing new features that need tests, or when…
от booch★ 18 звёзд на GitHubОб этом скилле
TDD Skill
This skill guides Test-Driven Development, focusing on writing tests as executable specifications before implementation.
Core Principles
Tests as Specifications
Tests are not just verification — they are executable specifications that document how the system should behave. A well-written test suite is living documentation.
API Design Through Testing
Tests are the first consumers of your API. Writing tests first means:
- You design the interface before implementation
- Awkward tests reveal awkward APIs
- The caller's perspective drives design decisions
Red-Green-Refactor
The classic TDD cycle:
- RED: Write a failing test
- GREEN: Write minimal code to pass
- REFACTOR: Improve while keeping tests green
This skill focuses on the RED phase. GREEN and REFACTOR are handled by /build and /refactor.
When to Use This Skill
- User explicitly requests TDD or "tests first"
- Implementing new behavior that needs verification
- Fixing a bug (write a test that reproduces it first)
- Refactoring (ensure tests exist before changing code)
Test Writing Process
1. Understand the Requirement
Before writing any test:
- What behavior is being specified?
- What are the inputs and expected outputs?
- What edge cases exist?
- What errors should be handled?
If unclear, ask clarifying questions first.
2. Design the API
Think about how the test will call the code:
# What interface would be convenient?
result = Calculator.add(2, 3) # Simple and clear
# vs.
calc = Calculator.new
calc.set_operand1(2)
calc.set_operand2(3)
result = calc.perform_addition # Awkward
Let the test drive the API toward simplicity.
3. Write the Test
Structure using AAA (Arrange-Act-Assert):
describe Calculator do
describe "#add" do
it "returns the sum of two positive integers" do
# Arrange
calculator = Calculator.new
# Act
result = calculator.add(2, 3)
# Assert
expect(result).to eq(5)
end
end
end
4. Verify the Test Fails
Run the test to confirm it fails for the right reason:
- ✅
NameError: uninitialized constant Calculator— Good, class doesn't exist - ✅
NoMethodError: undefined method 'add'— Good, method doesn't exist - ❌ Test passes — Something is wrong, the behavior already exists
5. Present for Review
Before implementation:
I've written these tests to specify the behavior:
[tests]
They verify:
- [behavior 1]
- [behavior 2]
The tests currently fail because [reason].
Ready to implement?
Test Quality Guidelines
One Behavior Per Test
Each test should have one reason to fail:
# Good: One behavior
it "returns nil when the key doesn't exist" do
expect(cache.get("missing")).to be_nil
end
# Bad: Multiple behaviors
it "handles missing keys and expired keys" do
expect(cache.get("missing")).to be_nil
expect(cache.get("expired")).to be_nil
end
Descriptive Names
Test names should read as specifications:
# Good: Describes behavior
it "raises ArgumentError when amount is negative"
# Bad: Describes implementation
it "calls validate_amount method"
Avoid Database When Possible
Don't hit the database unless testing database behavior:
# Good: In-memory object
user = User.new(name: "Craig", role: :admin)
# Avoid: Database persistence
user = User.create!(name: "Craig", role: :admin)
Minimal Mocking
Prefer real objects over mocks. When mocking is necessary:
- Mock roles/interfaces, not concrete implementations
- Keep mock setup simple
- Complex mocking often signals design problems
Language-Specific Patterns
Ruby (RSpec)
RSpec.describe ClassName do
describe "#method_name" do
context "when condition" do
it "behaves this way" do
# Arrange
subject = ClassName.new(dependency: fake_dependency)
# Act
result = subject.method_name(args)
# Assert
expect(result).to eq(expected)
end
end
end
end
JavaScript (Jest/Vitest)
describe("ClassName", () => {
describe("methodName", () => {
it("behaves this way when condition", () => {
// Arrange
const subject = new ClassName({ dependency: fakeDependency });
// Act
const result = subject.methodName(args);
// Assert
expect(result).toBe(expected);
});
});
});
Integration with Workflow
This skill produces tests. Related skills/commands:
/build— Implement code to pass the tests/refactor— Improve code while keeping tests green/review— Code review after implementation
Установить tdd в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл tdd?
Test-Driven Development methodology. Use this skill when writing tests, when the user asks for TDD, when implementing new features that need tests, or when the user says "write tests first" or similar. This skill focuses on the RED phase — writing failing tests that specify behavior.
Как установить скилл tdd?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tdd запускает скрипты?
Нет, скилл состоит только из инструкций (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