com um clique
tdd
Red-green-refactor test-driven development.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Red-green-refactor test-driven development.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Post-implementation integrity and quality audit.
Session-start skill discovery protocol.
Structured root-cause investigation for bugs and failures.
Execute implementation plan task-by-task inline.
Complete work with merge, PR, or cleanup options.
Integrity guardrails during code implementation.
Baseado na classificação ocupacional SOC
| name | tdd |
| description | Red-green-refactor test-driven development. |
No production code exists without a failing test that demanded it. Code written before its test gets deleted — not kept as reference, not adapted, not glanced at. Start clean from the test.
One test. One behavior. Descriptive name.
test('rejects empty email with validation error', async () => {
const result = await submitForm({ email: '' });
expect(result.error).toBe('Email required');
});
Requirements:
npm test path/to/test.test.ts
Confirm:
If it passes: the behavior already exists. Revise the test. If it errors: fix the error, re-run until it fails for the right reason.
Write the least code that makes the test pass. Nothing speculative. No options bags, no configurability, no "while I'm here" improvements.
function submitForm(data: FormData) {
if (!data.email?.trim()) {
return { error: 'Email required' };
}
// existing logic...
}
npm test path/to/test.test.ts
Confirm:
If the new test fails: fix implementation, not the test. If other tests break: fix the regression now.
Only after green. Remove duplication, improve naming, extract helpers. Verify tests remain green after every change. Do not introduce new behavior.
Next behavior, next failing test.
Tests written after implementation pass on first run. A test that never failed has two problems:
"Tests after" answer "what does this code do?" — "Tests before" answer "what should this code do?" These are different questions with different coverage characteristics.
Deleting existing implementation to restart with TDD is not waste. The sunk time is gone. Retaining code that lacks a red-green lineage means carrying unverified assumptions forward.
| Rationalization | Counter |
|---|---|
| "Too simple to need a test" | Simple code breaks. The test takes seconds. |
| "I'll add tests after" | Post-hoc tests pass immediately — that proves nothing. |
| "Already tested manually" | Manual checks leave no record and cannot re-run. |
| "Deleting N hours of work is wasteful" | Sunk cost. Unverified code is the actual waste. |
| "Keep it as reference, write tests first" | You will adapt it. That is testing after. Delete. |
| "Need to explore first" | Explore, then discard the spike and start with a test. |
| "Hard to test means unclear requirements" | Hard to test means hard to use. Simplify the interface. |
| "TDD slows me down" | Debugging without tests is slower. |
| "Existing code has no tests" | New changes get tests. Legacy is not an exemption. |
Any of these indicate the cycle was broken. Delete the untested code and restart:
| Property | Indicator |
|---|---|
| Focused | One behavior per test. "and" in the name signals it should split. |
| Descriptive | Name states expected behavior in plain language. |
| Intent-revealing | Test demonstrates the desired API, not internal mechanics. |
| Deterministic | No dependence on timing, execution order, or external state. |
| Boundary-mocked | Mocks exist only at I/O edges (network, filesystem, clock). Internal modules use real instances. |
| Symptom | Response |
|---|---|
| Cannot figure out what to test | Write the assertion first. Design the API you wish existed. |
| Test requires excessive setup | The design is too coupled. Simplify the interface. |
| Everything needs mocking | Dependency injection missing. Refactor to inject collaborators. |
| Test is more complex than the code | Extract test helpers. If still complex, the production design needs simplifying. |
Every bug fix starts with a failing test that reproduces the defect. The test proves the fix works and guards against recurrence. No exceptions.
Consult @references/testing-anti-patterns.md before introducing mocks or test utilities. Key traps:
Incomplete checklist means incomplete TDD. Go back and fill the gaps.