What is test-first vs test-last development?
Answer
Test-last (traditional): write production code first, then write tests to verify it. Problems: (1) Tests are shaped by the implementation rather than the requirements. (2) Tests verify what the code does, not what it should do. (3) Code is not written with testability in mind — harder to unit test. (4) Tests are often skipped when under time pressure. Test-first (TDD): write tests before code. Benefits: (1) Tests define behavior from requirements perspective. (2) Code is designed for testability from the start. (3) Tests are guaranteed to exist. (4) Red-green cycle gives immediate feedback. Which is better: for complex business logic with clear requirements — test-first (TDD) produces better-designed, better-tested code. For exploratory or UI prototyping work — test-last is often more pragmatic. Both are vastly better than no tests. Even in test-last workflows, writing tests immediately after (not months later) captures the context and produces better tests.