tdd
Skill42 starsChanged 17 days agoMITView on GitHub
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.
194 other projects use a version of this.
Adopted by
Most recently taken up by
- ishandutta2007/Awesome-Claude-Skillstheir own version, first seen Nov 8, 2026
- trpc/trpctheir own version, first seen Nov 8, 2026
- wowyuarm/dsh-agent-teamtheir own version, first seen Nov 8, 2026
- Contexera/dsh-agent-teamtheir own version, first seen Nov 8, 2026
- Dimon94/dveritytheir own version, first seen Nov 8, 2026
- Dimon94/skillstheir own version, first seen Nov 8, 2026
Used with
Projects with it also use capture-learning-tools, design-frontend-dev and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
The-Vibe-CompanySkillcapture-learning-tools
Turn technical conversations, bugs, CI failures, review comments,
Also in 5 projects that use this
The-Vibe-CompanySkilldesign-frontend-dev
Clean Impeccable frontend design skill. Use when the user wants to
Also in 5 projects that use this
tristanphvnSkillketchup-video
Catch the user up like /keel:ketchup, with a short silent video of slides for what happened and the waiting calls as text under it. Use for /keel:ketchup-video.
Also in 14 projects that use this
jaydubya818Skillfigure-it-out
Use when novel or multi-phase work needs an auditable workflow and no narrower playbook fits.
Also in 54 projects that use this
jaydubya818Skillprinciple-laziness-protocol
Apply when a refactor is adding wrappers or abstractions instead of simplifying.
Also in 45 projects that use this
- +2 more from The-Vibe-Company
- +5 more from jaydubya818
Other versions194 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 194
- mattpocock/skills★ 309ksame name
- trpc/trpc★ 41ksame name
- Yeachan-Heo/oh-my-claude-sisyphus★ 41ksame name
- Yeachan-Heo/oh-my-claudecode★ 41ksame name
- QuivrHQ/quivr★ 40ksame name
- The-Vibe-Company/quivr★ 40ksame name
- ccusage/ccusage★ 19ksame name
- ryoppippi/ccusage★ 19ksame name
- MODSetter/SurfSense★ 17ksame name
- GreyDGL/PentestGPT★ 16ksame name
184 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository44 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- phd-qualifierSkill
- citation-verifierSkill
- scientific-writingSkill
- brainstormingSkill
- elevenlabsSkill
- image-generationSkill
- presentationsSkill
- video-storytellingSkill
- code-reviewerSkill
- ralph-wiggumSkill
- version-controlSkill
- opentrons-absorbance-readerSkill
- opentrons-gripperSkill
- opentrons-heater-shakerSkill
- opentrons-magnetic-blockSkill
- opentronsSkill
- opentrons-temperature-moduleSkill
- opentrons-thermocyclerSkill
- planningSkill
- claude-lightSkill
- emacs-lispSkill
- fairchemSkill
- idaesSkill
- materials-propertiesSkill
- pycalphadSkill
- pymatgenSkill
- python-aseSkill
- python-best-practicesSkill
- python-jaxSkill
- python-multiobjective-optimizationSkill
- python-optimizationSkill
- python-plottingSkill
- python-regression-statisticsSkill
- vaspSkill
- pycseSkill
- elnSkill
- literature-reviewSkill
- materials-databasesSkill
- scientific-data-extractionSkill
- scientific-reviewerSkill
- scientific-workflowsSkill
- design-of-experimentsSkill
- troubleshootingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
41 rules. 0 are common, 37 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 186 edited versions we read keep these.
37
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Write test that specifies that behavior
- Distinctive: line 24
Run test to verify it fails for the right reason
- Distinctive: line 25
If test passes unexpectedly, test is wrong
- Distinctive: line 28
Write minimal code to make test pass
- Distinctive: line 29
Don't worry about perfection yet
- Distinctive: line 31
Run test to verify it passes
- Distinctive: line 37
Run tests after each change to ensure still passing
- Distinctive: line 40
Commit when tests are green
- Distinctive: line 42
Start cycle again with new test
- Distinctive: line 51
Test defines what "done" means
- Distinctive: line 57
Don't add features not tested
- Distinctive: line 62
Keep tests passing during refactoring
- Distinctive: line 64
Run tests after each refactoring step
- Distinctive: line 67
After writing test (should fail)
- Distinctive: line 68
After writing implementation (should pass)
- Distinctive: line 69
After each refactoring step (should stay green)
- Distinctive: line 80
Test design and organization
- Distinctive: line 87
Assert: - Verify the results
- Distinctive: line 104
Public interface: - Test behavior users depend on
- Distinctive: line 111
Private implementation details: - Test behavior, not internals
- Distinctive: line 114
Framework code: - Test your code, not the framework
- Distinctive: line 120
Prefer multiple small tests over one large test
- Distinctive: line 125
Self-documenting: - Test shows how code should be used
- Distinctive: line 126
Minimal setup: - Only what's needed for this test
- Distinctive: line 132
No shared mutable state between tests
- Distinctive: line 167
What: Test individual functions/methods in isolation
- Distinctive: line 178
What: Test multiple components working together
- Distinctive: line 189
What: Test complete user workflows
- Distinctive: line 238
Your own code: - Prefer real objects for your code
- Distinctive: line 240
Logic being tested: - Don't mock what you're testing
- Very specific: line 329
Test files: test_*.py, *_test.py, test-*.el
- Very specific: line 330
Test functions: Start with test_ or ert-deftest
- Very specific: line 331
Test classes: Test* (if using classes)
- Distinctive: line 344
Ensure all tests are green: before starting
- Distinctive: line 347
Commit frequently: - When tests pass
- Distinctive: line 361
Update test to test behavior instead
- Distinctive: line 387
Don't test just to increase coverage
- Very specific: line 395
Use scripts/coverage_analyzer.py to identify coverage gaps.
- Distinctive: line 408
assets/templates/: Test file templates for multiple languages
- Distinctive: line 432
Only refactor when green
- Distinctive: line 435
Don't add features
“Common” is measured: kept by at least 6 in 10 of the 186 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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 # AssertGiven-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
- Verifying system as a whole
- Smoke tests for deployment
Example: test_user_can_register_and_login()
Test Pyramid:
/\ ← Few E2E tests (slow, brittle)
/ \
/ IT \ ← Some Integration tests
/______\
/ Unit \ ← Many Unit tests (fast, focused)
/__________\TDD Red-Green-Refactor Example
Goal: Implement factorial function
Iteration 1 - Base case:
- RED:
test_factorial_of_zero_is_one()→ ❌ factorial not defined - GREEN:
def factorial(n): return 1→ ✅ Passes - REFACTOR: Nothing yet. Commit.
Iteration 2 - Positive numbers:
- RED:
test_factorial_of_five()expects 120 → ❌ Got 1 - GREEN: Implement loop to calculate factorial → ✅ Passes
- REFACTOR: Use recursion for elegance → ✅ Still passes. Commit.
Iteration 3 - Error handling:
- RED:
test_factorial_negative_raises_error()→ ❌ No error raised - GREEN: Add if n < 0: raise ValueError → ✅ All tests pass
- REFACTOR: Add docstring → ✅ Still passes. Commit.
Done! Function is complete, fully tested, documented. Three test-driven iterations.
Mocking and Test Doubles
When to Mock
- External dependencies - Databases, APIs, file systems
- Slow operations - Network calls, large computations
- Unpredictable behavior - Random, time-dependent, external state
- Hard to trigger scenarios - Error conditions, edge cases
When NOT to Mock
- Your own code - Prefer real objects for your code
- Simple objects - Data classes, value objects
- Logic being tested - Don't mock what you're testing
Types of Test Doubles
Mock - Programmed with expectations, verifies interactions Stub - Provides canned responses, doesn't verify Fake - Working implementation, simpler than real Spy - Records calls, allows verification after
See references/test-design-patterns.md for detailed mocking strategies.
Common TDD Anti-Patterns
Don't:
❌ Write implementation before test - Defeats TDD purpose
❌ Write multiple tests before making them pass - Stay in rhythm (one test, make it pass, next test)
❌ Refactor with red tests - Only refactor when green
❌ Test implementation details - Test behavior, not internals
❌ Skip refactor step - Technical debt accumulates
❌ Write tests that are hard to understand - Tests are documentation
❌ Create dependencies between tests - Tests must be independent
❌ Mock everything - Use real objects when practical
❌ Fake it with hardcoded values forever - "Fake it till you make it" is temporary
❌ Write slow tests - Slow test suite won't be run frequently
Test Naming Conventions
Good test names are descriptive and specific:
Pattern: test_<function>_<scenario>_<expected_result>
test_add_two_positive_numbers_returns_sum()
test_add_with_negative_number_returns_correct_result()
test_add_with_zero_returns_other_number()Pattern: should_<expected_behavior>_when_<condition>
should_return_empty_list_when_no_items_match()
should_raise_error_when_input_is_null()
should_calculate_discount_when_user_is_premium()Pattern: <behavior>_<state>_<expected>
(ert-deftest save-buffer-modified-saves-to-file ())
(ert-deftest load-file-missing-raises-error ())Test name should:
- Describe what's being tested
- Describe the scenario/condition
- Describe expected outcome
- Be readable as documentation
Test Organization
Directory Structure
Python:
project/
├── src/
│ └── calculator.py
└── tests/
├── __init__.py
├── test_calculator.py
└── conftest.py # pytest fixturesElisp:
package/
├── my-package.el
└── test/
└── test-my-package.elNaming Conventions
- Test files:
test_*.py,*_test.py,test-*.el - Test functions: Start with
test_orert-deftest - Test classes:
Test*(if using classes)
Grouping Tests
- One test file per source file (generally)
- Group related tests in same file
- Separate unit/integration/e2e tests
See language-specific references for detailed organization patterns.
Refactoring with Tests
Safe Refactoring Process
- Ensure all tests are green before starting
- Make small changes - One refactoring at a time
- Run tests after each change - Catch breaks immediately
- Commit frequently - When tests pass
- Don't add features while refactoring - Separate concerns
Common Refactorings
- Extract function (break up large functions)
- Rename for clarity
- Remove duplication (DRY)
- Simplify conditional logic
- Extract variable for readability
- Inline unnecessary abstraction
When Tests Break During Refactoring
If test is testing implementation detail:
- Update test to test behavior instead
- Make test more resilient to changes
If test is testing behavior:
- Fix the code, not the test
- Behavior shouldn't change during refactoring
If too many tests break:
- Change is too large, revert
- Make smaller incremental changes
See references/refactoring-with-tests.md for detailed guidance.
Test Coverage
Coverage measures which code is executed by tests, not whether tests are good.
Types of Coverage
- Line coverage - Which lines executed
- Branch coverage - Which paths taken
- Function coverage - Which functions called
Coverage Goals
- Aim for high coverage (80%+) but not 100%
- 100% coverage doesn't mean bug-free
- Focus on critical code paths
- Don't test just to increase coverage
Using Coverage Tools
- Python: pytest-cov, coverage.py
- JavaScript: Jest with coverage
- Java: JaCoCo
- Ruby: SimpleCov
Use scripts/coverage_analyzer.py to identify coverage gaps.
Using Supporting Resources
Additional resources in this skill:
- references/python-tdd.md: Comprehensive Python testing guide (pytest, unittest, mocking, async)
- references/elisp-tdd.md: Comprehensive Elisp testing guide (ERT, Buttercup, interactive functions)
- references/general-tdd.md: Universal TDD principles for any language
- references/test-design-patterns.md: What to test, test organization, anti-patterns
- references/refactoring-with-tests.md: Safe refactoring process and common refactorings
- scripts/test_template_generator.py: Generate test file boilerplate
- scripts/coverage_analyzer.py: Analyze coverage reports
- assets/templates/: Test file templates for multiple languages
Quick Reference
TDD Cycle:
- RED - Write failing test
- GREEN - Make it pass (minimal code)
- REFACTOR - Improve while keeping green
- REPEAT
Test Structure:
- Arrange (setup)
- Act (execute)
- Assert (verify)
Test Principles:
- Test first
- One test at a time
- One behavior per test
- Independent tests
- Fast tests
- Readable tests
Refactoring Rules:
- Only refactor when green
- Small changes
- Run tests frequently
- Don't add features
Remember: TDD is a discipline. The value comes from following the cycle strictly. Test first. See it fail. Make it pass. Refactor. Repeat. The rhythm creates quality code.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

