test-driven-development
Qué hace
Guía a un agente de IA por una forma de construir software basada en pruebas, escribiendo una prueba antes del código que cubre. Es para desarrolladores que quieren código que funcione y una prueba de que cada cambio hace lo que debe.
Cuándo usarla
- ✓Cuando pides una función nueva, una corrección de error o un cambio de comportamiento en código.
- ✓Cuando quieres refactorizar código con seguridad y con pruebas ya en su sitio.
- ✓Cuando un error debe quedar demostrado como corregido con una prueba que antes fallaba.
Link de la skill
https://github.com/obra/superpowers/blob/main/skills/test-driven-development/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Añade una función que permita a los usuarios exportar su lista como CSV, y escribe primero las pruebas.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill escribe una prueba para el nuevo comportamiento, la ejecuta para confirmar que falla y luego escribe el código mínimo necesario para que pase. Después ordena el código manteniendo las pruebas en verde.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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 your human partner):
- 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
digraph tdd_cycle {
rankdir=LR;
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
verify_red [label="Verify fails\ncorrectly", shape=diamond];
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
verify_green [label="Verify passes\nAll green", shape=diamond];
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
next [label="Next", shape=ellipse];
red -> verify_red;
verify_red -> green [label="yes"];
verify_red -> red [label="wrong\nfailure"];
green -> verify_green;
verify_green -> refactor [label="yes"];
verify_green -> green [label="no"];
refactor -> verify_green [label="stay\ngreen"];
verify_green -> next;
next -> red;
}
RED - Write Failing Test
Write one minimal test showing what should happen.
<Good> ```typescript test('retries failed operations 3 times', async () => { let attempts = 0; const operation = () => { attempts++; if (attempts < 3) throw new Error('fail'); return 'success'; };const result = await retryOperation(operation);
expect(result).toBe('success'); expect(attempts).toBe(3); });
Clear name, tests real behavior, one thing
</Good>
<Bad>
```typescript
test('retry works', async () => {
const mock = jest.fn()
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValueOnce('success');
await retryOperation(mock);
expect(mock).toHaveBeenCalledTimes(3);
});
Vague name, tests mock not code </Bad>
Requirements:
- One behavior
- Clear name
- Real code (no mocks unless unavoidable)
Verify RED - Watch It Fail
MANDATORY. Never skip.
npm test path/to/test.test.ts
Confirm:
- Test fails (not errors)
- Failure message is expected
- Fails because feature missing (not typos)
Test passes? You're testing existing behavior. Fix test.
Test errors? Fix error, re-run until it fails correctly.
GREEN - Minimal Code
Write simplest code to pass the test.
<Good> ```typescript async function retryOperation<T>(fn: () => Promise<T>): Promise<T> { for (let i = 0; i < 3; i++) { try { return await fn(); } catch (e) { if (i === 2) throw e; } } throw new Error('unreachable'); } ``` Just enough to pass </Good> <Bad> ```typescript async function retryOperation<T>( fn: () => Promise<T>, options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void; } ): Promise<T> { // YAGNI } ``` Over-engineered </Bad>Don't add features, refactor other code, or "improve" beyond the test.
Verify GREEN - Watch It Pass
MANDATORY.
npm test path/to/test.test.ts
Confirm:
- Test passes
- Other tests still pass
- Output pristine (no errors, warnings)
Test fails? Fix code, not test.
Other tests fail? Fix now.
"Other tests" means the project's suite, not just your file. A
green run of the test you wrote is not a green suite. Before you call
the change done, run the project's test command (bare pytest,
npm test, cargo test — whatever the repo uses) even when your task
named only one test file. A scope statement in your task bounds the
deliverable, not your verification. Any failure that run shows —
including one you didn't cause — goes in your report by name; a red
test you watched scroll past and didn't mention is a report falsified
by omission.
REFACTOR - Clean Up
After green only:
- Remove duplication
- Improve names
- Extract helpers
Keep tests green. Don't add be
Preguntas frecuentes
¿Puede saltarse las pruebas en un prototipo rápido?
Los prototipos desechables y el código generado son excepciones, pero la skill te pregunta antes de saltarse las pruebas.
¿Qué pasa si el código se escribió antes que su prueba?
La skill indica que ese código debe borrarse y reescribirse a partir de las pruebas, para que la prueba realmente guíe el diseño.
¿Por qué ver fallar la prueba?
Una prueba que nunca se vio fallar podría no estar comprobando lo correcto.
Detalles
Descripción original del autor
Use when implementing any feature or bugfix, before writing implementation code
repo: obra/superpowers
Popularidad
- Estrellas en GitHub
- 311 mil
- Posición en el ranking
- #95
- Licencia
- MIT
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
brainstorming
311 milAyuda a tu agente a descubrir lo que realmente quieres antes de construir nada nuevo, haciendo preguntas concretas y presentando opciones claras.
executing-plans
311 milAyuda a tu agente a ejecutar paso a paso un plan de implementación escrito en la sesión actual, probando cada paso antes de avanzar al siguiente.
finishing-a-development-branch
311 milAyuda a tu agente a cerrar código terminado ejecutando las pruebas y ofreciendo opciones claras para fusionar, abrir un pull request o conservar la rama.
receiving-code-review
311 milAyuda a tu agente a valorar con cuidado los comentarios de una revisión de código, comprobando cada punto contra el código antes de cambiar nada.
Skills parecidas
migrate-to-shoehorn
310 milSustituye los casts de tipo arriesgados de tus archivos de prueba por la librería shoehorn, para que las pruebas usen datos parciales y sigan pasando las comprobaciones de tipos.
cpp-testing
280 milHace que tu agente escriba y mejore pruebas para código C++. Ayuda a configurar las herramientas de testing y a corregir errores.
csharp-testing
280 milAyuda a tu agente a crear pruebas para código C# y .NET. Usa buenas prácticas para que las pruebas sean eficientes y fiables.