Test-Driven Development (TDD) — Red-Green-Refactor in Java
Fast recall
Quick revision
Core answer
Whether the candidate understands TDD's red-green-refactor cycle and when it adds value.
Writing full implementation first and claiming TDD because tests exist.
Explain that TDD is a design technique, not a testing technique, and discuss when it helps vs when it's overhead.
Interview-ready guide
Interview answer
TDD is red-green-refactor: write a failing test first, write the minimum code to pass it, then refactor with the test as a safety net. The cycle repeats — each test adds one behavior, and the implementation grows incrementally.
The misconception is that TDD is about testing. It's actually a design technique. By writing the test first, you design the API before the implementation — what the method takes, what it returns, what it throws. The test is a specification.
TDD works best for business logic with clear inputs and outputs — calculators, validators, state machines. It's less useful for framework-driven code like controllers and configuration, where the design is dictated by Spring, not by your domain.
For bug fixes, TDD is invaluable: write a test that reproduces the bug, verify it fails, fix it, verify it passes. The test prevents regression permanently.
Test-Driven Development (TDD) — Red-Green-Refactor in Java
Direct Answer
TDD means writing a failing test first, implementing the minimum to pass it, then refactoring. The test drives API design before implementation.
Common Mistakes & Pitfalls
Writing full implementation first and claiming TDD because tests exist.
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.