TDD (Test-Driven Development)
// Definition
Write a failing test first, write the minimum code to make it pass, refactor. Drives design through tests rather than testing afterward — and produces a thorough unit test suite as a byproduct.
// Code Example
// 1. RED — write a failing test first
test('add returns the sum of two numbers', () => {
expect(add(2, 3)).toBe(5);
});
// 2. GREEN — minimum code to pass
function add(a: number, b: number) {
return a + b;
}
// 3. REFACTOR — improve while keeping tests green
const add = (a: number, b: number): number => a + b;// Related terms
BDD (Behaviour-Driven Development)
Collaborative specification writing using human-readable scenarios (Given/When/Then) shared across product, dev, and QA. Often automated with Cucumber, SpecFlow, or similar tools.
ATDD (Acceptance Test-Driven Development)
Extends TDD by writing acceptance tests collaboratively with the customer or product team before implementation begins. Aligns the team on what 'done' looks like in concrete, testable terms.
Test Pyramid
A model for balancing test types: a wide base of fast unit tests, a smaller layer of integration tests, and a thin layer of slow end-to-end tests. Counters the inverted 'ice-cream cone' anti-pattern of UI-heavy suites.