# 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.

TDD Coach: Red-Green-Refactor, Tests That Fail Right is a paid AI agent skill on Agensi by Nguyen Duc Dung, in Testing & Debugging. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Nguyen Duc Dung](https://www.agensi.io/creators/nguyenddung)
- Category: [Testing & Debugging](https://www.agensi.io/skills/testing-debugging)
- Version: 1.0
- Last updated: 2026-11-30
- Security: scan passed (2026-11-30); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/tdd-coach-red-green-refactor-tests-that-fail-right
- Tags: testing, python, pytest, tdd, code-review

## 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
1. **Red phase:** The skill writes a single behavior-focused test and runs it to confirm a specific, meaningful failure.
2. **Green phase:** It writes the simplest possible production code, including hard-coded values if necessary, to pass.
3. **Refactor phase:** It cleans up the implementation while maintaining green status, ensuring no regressions occur.
4. **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 this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the TDD Coach: Red-Green-Refactor, Tests That Fail Right skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill change the way code is written compared to standard AI prompting?

This skill enforces a strict red-green-refactor loop where a failing test for a specific behavior must be confirmed before any production code is written. It prevents common issues like brittle test suites that mirror implementation rather than behavior.

### What software or tools are required to use this skill?

The skill is optimized for Python environments and expects the presence of pytest and uv. It assumes the project uses standard arrange-act-assert patterns and has a test runner available to verify results.

### Are there any types of testing that this skill is not suitable for?

This skill is designed for behavioral testing through public interfaces and is not suitable for UI-heavy visual testing or non-deterministic environments. It also requires a standard test runner like pytest to be accessible in the environment.

### How should I ask my agent to begin using this skill?

You can trigger this skill by asking your agent to implement a feature using TDD, write tests first, or follow a red-green-refactor cycle for a specific Python task. It is also useful when you need to fix a bug by first reproducing it with a targeted failing test.

### What kind of code quality and testing patterns can I expect as an output?

The skill delivers clean, refactored Python code where every line is justified by a passing test. It specifically avoids anti-patterns such as tautological assertions, mocking the system under test, or changing assertions to match incorrect outputs.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
