| name | tdd-workflow |
| description | Enforce a strict Test-Driven Development (TDD) execution sequence: write failing test, write minimal code, refactor code |
Test-Driven Development (TDD) Workflow Skill
When to activate
- Building a new feature or module from scratch where specifications are well-defined.
- Fixing a reported bug (writing a reproduction test first).
- Ensuring high test coverage and robust software design.
When NOT to use
- Exploratory coding or prototyping where requirements are highly volatile.
- UI/UX layout refinements or pure styling exercises (e.g. Tailwind updates).
Instructions
Follow the strict three-stage red-green-refactor lifecycle:
Stage 1: Red (Write a Failing Test)
- Do not write any implementation code yet.
- Define a new test in the test suite describing the expected input, conditions, and outputs.
- Run the test suite and verify that the new test fails (typically with a compilation error or assertion failure).
Stage 2: Green (Write Minimal Code)
- Write the absolute minimum implementation code necessary to make the failing test pass.
- Avoid over-engineering or writing extra helper functions not validated by the test suite.
- Run the tests and ensure the test suite compiles and runs successfully (green).
Stage 3: Refactor (Clean up the Code)
- Review the newly written code for code smells, duplicates, or readability issues.
- Clean up formatting, structure, and naming conventions without changing functional behavior.
- Verify that all tests remain green after refactoring.
Example
test("adds numbers correctly", () => {
expect(add(2, 3)).toBe(5);
});
export function add(a: number, b: number) {
return a + b;
}
export const add = (a: number, b: number): number => a + b;