tdd
БесплатноЗапускает вложенные скриптыНе проверенTest-Driven Development facilitation using the red-green-refactor cycle. Guides users through writing tests first, implementing minimal code to pass, and…
Об этом скилле
Test-Driven Development (TDD) Skill
Guide users through disciplined test-first development using the red-green-refactor cycle.
Core TDD Workflow
RED → GREEN → REFACTOR → REPEAT
RED: Write a Failing Test
- Identify next small behavior to implement
- Write test that specifies that behavior
- Run test to verify it fails for the right reason
- If test passes unexpectedly, test is wrong
GREEN: Make It Pass
- Write minimal code to make test pass
- Don't worry about perfection yet
- Simplest solution that works
- Run test to verify it passes
REFACTOR: Improve the Code
- Improve code quality while keeping tests green
- Remove duplication
- Improve names and structure
- Run tests after each change to ensure still passing
REPEAT
- Commit when tests are green
- Identify next behavior
- Start cycle again with new test
TDD Discipline
Critical rules to follow:
Test First (RED Phase)
- Always write test before implementation
- Resist urge to write code first
- Test defines what "done" means
- See test fail before making it pass
Minimal Implementation (GREEN Phase)
- Write simplest code to pass
- Don't over-engineer
- Don't add features not tested
- One test at a time
Refactor Only When Green
- Never refactor with failing tests
- Keep tests passing during refactoring
- Small, incremental improvements
- Run tests after each refactoring step
Run Tests Frequently
- After writing test (should fail)
- After writing implementation (should pass)
- After each refactoring step (should stay green)
- Before committing
When to Use This Skill
Activate for requests involving:
- "Use TDD for..." / "Test-driven development..."
- "Write tests first..." / "Red-green-refactor..."
- Developing new features test-first
- Learning TDD practices
- Setting up test infrastructure
- Test design and organization
Test Structure Patterns
Arrange-Act-Assert (AAA)
Arrange - Set up test data and environment Act - Execute the code under test Assert - Verify the results
def test_add_two_numbers():
calculator = Calculator() # Arrange
result = calculator.add(2, 3) # Act
assert result == 5 # Assert
Given-When-Then (BDD Style)
Given - Initial context/preconditions When - Action/event occurs Then - Expected outcome
Test Design Principles
What to Test
- Public interface - Test behavior users depend on
- Edge cases - Boundaries, empty inputs, max values
- Error conditions - Invalid inputs, exceptions
- Business logic - Core algorithms and rules
- Integration points - Where components interact
What NOT to Test
- Private implementation details - Test behavior, not internals
- Third-party libraries - Trust they work, test your usage
- Simple getters/setters - Unless they have logic
- Framework code - Test your code, not the framework
One Behavior Per Test
- Each test should verify single behavior
- Makes failures easier to diagnose
- Keeps tests focused and readable
- Prefer multiple small tests over one large test
Make Tests Readable
- Descriptive names -
test_add_returns_sum_of_two_positive_numbers - Clear structure - AAA or Given-When-Then
- Self-documenting - Test shows how code should be used
- Minimal setup - Only what's needed for this test
Keep Tests Independent
- Tests should not depend on each other
- Tests can run in any order
- Each test starts with clean state
- No shared mutable state between tests
See references/test-design-patterns.md for comprehensive guidance.
Language-Specific Guidance
For Python
See references/python-tdd.md for:
- pytest and unittest frameworks
- Fixtures and parametrized tests
- Mocking with unittest.mock
- Testing async code
- Coverage with pytest-cov
- Running and organizing tests
For Emacs Lisp
See references/elisp-tdd.md for:
- ERT (Emacs Lisp Regression Testing)
- Testing interactive functions
- Buffer manipulation testing
- Mocking with cl-letf
- Buttercup (BDD alternative)
- Running tests in Emacs and batch mode
For Other Languages
See references/general-tdd.md for:
- Finding testing frameworks
- Universal test patterns
- Common testing concepts
- Build tool integration
- Language-agnostic principles
Test Types and When to Use
Unit Tests
What: Test individual functions/methods in isolation
When:
- Testing pure functions
- Testing business logic
- Testing algorithms
- Fast, focused tests
Example: test_calculate_discount(price, percentage)
Integration Tests
What: Test multiple components working together
When:
- Testing database interactions
- Testing API calls
- Testing service integration
- Verifying components connect correctly
Example: test_user_service_saves_to_database()
End-to-End Tests
What: Test complete user workflows
When:
- Testing critical user paths
Установить tdd в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
*Вложенные файлы
FAQ
Что делает скилл tdd?
Test-Driven Development facilitation using the red-green-refactor cycle. Guides users through writing tests first, implementing minimal code to pass, and refactoring for quality. Use when users want to practice TDD, need help writing tests before code, are developing new features test-first, or want guidance on test structure and implementation. Triggers include 'use TDD,' 'test-driven development,' 'write tests first,' 'red-green-refactor,' or requests to develop functionality with tests.
Как установить скилл tdd?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tdd запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
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