test-driven-development
What it does
This skill makes your AI write tests before code for new features, bug fixes and behavior changes. It is for developers who want code that is covered by tests from the start.
When to use it
- āWhen you ask your AI to add a new feature or change how the code behaves.
- āWhen you ask your AI to fix a bug and want a test that proves the fix.
- āWhen you want to refactor code safely with tests in place.
Skill link
https://github.com/NousResearch/hermes-agent/blob/main/skills/software-development/test-driven-development/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentās skills folder.
Example of what to ask your AI
āAdd a retry feature to our upload function, and write the test first so we know it works.ā
5 new skills a week. 1 minute to read.
How it works
The skill follows a red-green-refactor cycle: write one small test and watch it fail, write the least code to pass it, then clean up. The AI deletes any code it wrote before the failing test.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Test-Driven Development (TDD)
Overview
Write the test first. Watch it fail. Write minimal code to pass.
Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.
Violating the letter of the rules is violating the spirit of the rules.
When to Use
Always:
- New features
- Bug fixes
- Refactoring
- Behavior changes
Exceptions (ask the user first):
- Throwaway prototypes
- Generated code
- Configuration files
Thinking "skip TDD just this once"? Stop. That's rationalization.
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over.
No exceptions:
- Don't keep it as "reference"
- Don't "adapt" it while writing tests
- Don't look at it
- Delete means delete
Implement fresh from tests. Period.
Red-Green-Refactor Cycle
RED ā Write Failing Test
Write one minimal test showing what should happen.
Good test:
def test_retries_failed_operations_3_times():
attempts = 0
def operation():
nonlocal attempts
attempts += 1
if attempts < 3:
raise Exception('fail')
return 'success'
result = retry_operation(operation)
assert result == 'success'
assert attempts == 3
Clear name, tests real behavior, one thing.
Bad test:
def test_retry_works():
mock = MagicMock()
mock.side_effect = [Exception(), Exception(), 'success']
result = retry_operation(mock)
assert result == 'success' # What about retry count? Timing?
Vague name, tests mock not real code.
Requirements:
- One behavior per test
- Clear descriptive name ("and" in name? Split it)
- Real code, not mocks (unless truly unavoidable)
- Name describes behavior, not implementation
Verify RED ā Watch It Fail
MANDATORY. Never skip.
# Use terminal tool to run the specific test
pytest tests/test_feature.py::test_specific_behavior -v
Confirm:
- Test fails (not errors from typos)
- Failure message is expected
- Fails because the feature is missing
Test passes immediately? You're testing existing behavior. Fix the test.
Test errors? Fix the error, re-run until it fails correctly.
GREEN ā Minimal Code
Write the simplest code to pass the test. Nothing more.
Good:
def add(a, b):
return a + b # Nothing extra
Bad:
def add(a, b):
result = a + b
logging.info(f"Adding {a} + {b} = {result}") # Extra!
return result
Don't add features, refactor other code, or "improve" beyond the test.
Cheating is OK in GREEN:
- Hardcode return values
- Copy-paste
- Duplicate code
- Skip edge cases
We'll fix it in REFACTOR.
Verify GREEN ā Watch It Pass
MANDATORY.
# Run the specific test
pytest tests/test_feature.py::test_specific_behavior -v
# Then run ALL tests to check for regressions
pytest tests/ -q
Confirm:
- Test passes
- Other tests still pass
- Output pristine (no errors, warnings)
Test fails? Fix the code, not the test.
Other tests fail? Fix regressions now.
REFACTOR ā Clean Up
After green only:
- Remove duplication
- Improve names
- Extract helpers
- Simplify expressions
Keep tests green throughout. Don't add behavior.
If tests fail during refactor: Undo immediately. Take smaller steps.
Repeat
Next failing test for next behavior. One cycle at a time.
Avoid Horizontal Slices
Do not write all tests first and then all implementation. That is horizontal slicing: RED becomes "write a pile of imagined tests" and GREEN becomes "make the pile pass." It produces brittle tests because the tests are designed before the implementation has taught you what behavior and interface actually matter.
Use vertical tracer bullets instead:
WRONG:
RED: test1, test2, test3, test4
GREEN: impl1, impl2, impl3, impl4
RIGHT:
REDāGREEN: test1āimpl1
REDāGREEN: test2āimpl2
REDāGREEN: test3āimpl3
A tracer bullet is one end-to-end behavior slice. It proves the path works, teaches you about the interface, and keeps each next test grounded in what you just learned.
Why Order Matters
"I'll write tests after to verify it works"
Tests written after code pass immediately. Passing immediately proves nothing:
- Might test the wrong thing
- Might test implementation, not behavior
- Might miss edge cases you forgot
- You never saw it catch the bug
Test-first forces you to see the test fail,
FAQ
Are there exceptions?
Yes. The skill says to ask first for throwaway prototypes, generated code and configuration files.
Why must the test fail first?
The skill says that if you did not watch the test fail, you do not know if it tests the right thing.
What if I already wrote the code?
The skill says to delete the code and start over from the tests.
Details
Original description by the author
TDD: enforce RED-GREEN-REFACTOR, tests before code.
Popularity
- GitHub stars
- 260k
- Ranking position
- #626
- License
- MIT
- Updated
- 11/2/2026
Comments
- ā¦
More skills from this repository
agent-merge-conflict-arbiter
260kSettles a git merge conflict between two agents' branches as a neutral third party, producing one merged result for the repo.
antigravity-cli
260kGuides you through installing, updating, and troubleshooting the Antigravity command line tool, including its plugins, sign-in, and sandbox.
blackbox
260kLets your agent hand a coding task to the Blackbox AI command line tool, which runs several AI models and picks the best result.
dynamic-workflow
260kTeaches your agent to run large batches of similar work as a saved script, so only verified results return to the main conversation.
Similar skills
test-driven-development
311kTeaches your agent to write a failing test first, watch it fail, then write the smallest code that passes, before building any feature or fix.
verification-before-completion
311kTeaches your agent to run real checks and read their output before claiming that a task, fix, or build is complete or passing.
migrate-to-shoehorn
310kReplaces risky type casts in your test files with the shoehorn library, so tests can use partial data and still pass type checks.