Engineering Practice
TDD: multiple-choice review
Six questions that cut across the whole unit. Each one is a decision a senior makes under real constraints — a fragile suite, an unknown vendor, a green CI sitting on a 67% mutation score — not a definition to recite.
Confirm you can connect the unit’s spine: test-first as design pressure, the boundary rule that tames doubles, properties over examples, when TDD’s tax is worth paying, and mutation score as the metric coverage can’t fake.
You write a test first and find you must construct four collaborators — DB, payment, email, flags — just to exercise one cancel-order rule. What is the test actually telling you?
A PriceCalculator uses a pure TaxRule you own and a third-party CurrencyApi over HTTP. How should you double each for a robust unit test?
A money formatter has 94% coverage and eight months of green CI, then double-charges a customer on a value ending in .005. Why did every example test miss it, and what would have caught it?
A senior insists on full TDD for a two-day spike to evaluate an unfamiliar vendor API and decide whether to sign. Why is this the wrong call?
A billing module shows 100% line coverage but a 67% mutation score, with a surviving '>' → '>=' boundary mutant. How do you read this?
Across the unit, what is the through-line that distinguishes a test suite that is an asset from one that is a liability?
The unit’s spine is one judgment loop. Test-first is design pressure — a hard-to-construct object is the design review, not an obstacle to mock around. The boundary rule tames doubles: mock what you can’t run, use real objects for code you own, assert state. Example tests cover only inputs you imagined, so properties generate the rest and shrink failures to a minimal counterexample. TDD’s tax (15–22%) pays off in proportion to spec stability and code lifetime — spike the unknown, then rebuild. And mutation score is the honest metric: coverage proves a line ran, a survived mutant proves a test would have missed the bug. Through all of it, couple to behavior, never to structure.