| name | testing-tdd-workflow |
| description | Apply when implementing new features, fixing bugs, or refactoring code. TDD ensures tests drive design and all code is covered. |
| version | 1.0.0 |
| tokens | ~600 |
| confidence | high |
| sources | ["https://martinfowler.com/bliki/TestDrivenDevelopment.html","https://blog.cleancoder.com/uncle-bob/2014/12/17/TheCyclesOfTDD.html"] |
| last_validated | "2025-01-10T00:00:00.000Z" |
| next_review | "2025-01-24T00:00:00.000Z" |
| tags | ["testing","tdd","workflow","methodology"] |
When to Use
Apply when implementing new features, fixing bugs, or refactoring code. TDD ensures tests drive design and all code is covered.
Patterns
Pattern 1: Red-Green-Refactor Cycle
RED: Write failing test (test what, not how)
GREEN: Write minimal code to pass
REFACTOR: Improve code, keep tests green
REPEAT: Next behavior
Source: https://martinfowler.com/bliki/TestDrivenDevelopment.html
Pattern 2: Test Structure (AAA)
it('should calculate total with discount', () => {
const cart = new Cart();
cart.add({ price: 100, quantity: 2 });
const total = cart.calculateTotal(0.1);
expect(total).toBe(180);
});
Pattern 3: One Assertion Per Test
it('should add item to cart', () => {
cart.add(item);
expect(cart.items).toContain(item);
});
it('should update cart count', () => {
cart.add(item);
(cart.).();
});
(, { });