- Home
- Skills
- Testing & Debugging
- TDD Coach: Red-Green-Refactor, Tests That Fail Right
Works with the AI Agents you already use
TDD Coach: Red-Green-Refactor, Tests That Fail Right
Turn your agent into a disciplined TDD partner: one test that fails for the right reason, the minimal code to pass, then refactor on green. Flags tautological asserts, over-mocking and brittle snapshots. Any language.
$5
TDD Coach: Red-Green-Refactor, Tests That Fail Right
Example session with this skill installed
Apply TDD to create a function that calculates a loyalty discount. 5% for orders over $100, 10% for over $500. No discount below $100.
- Read your context and instructions
- Compiled the tdd coach
I have followed the TDD loop to implement the loyalty discount logic. First, I wrote failing tests for each threshold, then implemented the minimal logic to pass, and finally refactored for clarity.
Loyalty Discount Implementation
import pytest
# Production Code
def get_loyalty_discount(amount: float) -> float:
"""Calculates discount based on order amount."""
if amount >= 500:
return 0.10
if amount >= 100:
return 0.05
return 0.0
# Test Suite
def test_returns_zero_discount_below_one_hundred():
assert get_loyalty_discount(99.99) == 0.0
def test_returns_five_percent_at_one_hundred():
assert get_loyalty_discount(100.0) == 0.05
def test_returns_five_percent_between_one_hundred_and_five_hundred():
assert get_loyalty_discount(450.0) == 0.05
def test_returns_ten_percent_at_five_hundred():
assert get_loyalty_discount(500.0) == 0.10
def test_returns_ten_percent_above_five_hundred():
assert get_loyalty_discount(1200.0) == 0.10
Next steps
- Run
uv run pytest tests/test_discounts.py -qto verify the full suite passes. - Integrate this function into the checkout service layer.
- Add a test case for negative input values to handle error boundaries.
Connects securely to your tools. The creator never sees your data.
About this skill
Writing tests after the fact leads to brittle suites that verify implementations rather than behaviors. This skill enforces a strict red-green-refactor loop to ensure every line of code is justified by a failing test.
What it does
- Enforces TDD cycles by requiring a failing test for the missing behavior before any production code is written.
- Validates failure reasons to ensure tests fail due to missing logic rather than configuration or import errors.
- Simplifies implementations by encouraging the minimal code necessary to pass the current test.
- Guides refactoring to clean up duplication and naming only when the suite is in a green state.
- Prevents anti-patterns like tautological assertions, mocking the system under test, or brittle snapshots.
How it works
- Red phase: The skill writes a single behavior-focused test and runs it to confirm a specific, meaningful failure.
- Green phase: It writes the simplest possible production code, including hard-coded values if necessary, to pass.
- Refactor phase: It cleans up the implementation while maintaining green status, ensuring no regressions occur.
- Verification: It runs the specific test during iteration and the full suite before finalizing the task.
Frameworks & tools
This skill is optimized for Python environments using pytest and uv. It utilizes arrange-act-assert patterns and standard test runners.
Why this beats prompting it yourself
Generic prompts often result in the AI writing the code first and then a test that mirrors it, which misses the point of TDD. This skill forces a vertical slice approach where tests drive the architecture and every assertion is verified to fail before it passes.
Use cases
- Implementing a new API endpoint or business logic layer from scratch.
- Fixing a bug by first reproducing it with a targeted failing test case.
- Refactoring complex legacy functions while ensuring behavior remains unchanged.
- Adding edge case handling for empty inputs, boundary values, or external API failures.
Known limitations
This skill focuses on behavioral testing through public interfaces and may not be suitable for UI-heavy visual testing or non-deterministic environments. It assumes a standard test runner like pytest is available.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 4 days ago
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in Testing & Debugging
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.