What to test and why · mid
TDD and writing tests during a coding interview
Test-driven development is red, green, refactor: write a failing test for the next small behaviour, make it pass simply, then clean up; in interviews, listing test cases before coding and running them as you go shows senior habits even when you do not do strict TDD.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Red: write one small failing test. Green: write the simplest code that passes. Refactor: improve names and structure with the tests still green.
- In an interview, say the test list out loud first: normal case, empty input, one item, duplicates, large input, invalid input, async/timing cases.
- Some companies grade with hidden tests (Coinbase, some Swiggy rounds): handle edge cases and read the provided tests carefully.
- For async utilities (debounce, retry, promise pool), mention fake timers and show one test; for UI components, show one RTL test with getByRole and userEvent.
- Keep tests readable: Arrange, Act, Assert; one behaviour per test; clear names ('returns 0 for empty cart').
The red pen
Common traps: mistake → fix
Mistake: "I'll add tests at the end if there is time"
Fix: there is never time; list cases first and test while you build.
Mistake: "TDD means writing all tests before any code"
Fix: it is one small test at a time.
Easy to hard
Questions interviewers ask, easy to hard
- Do you practise TDD? How?
- Before you code this LRU cache, what test cases would you write?
- How would you test the debounce you just wrote?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.