JUnit 5 & Mockito: Testing That Catches Bugs
It's the Monday after Black Friday. Your team's checkout service has been live for three weeks, and every test you have is a person clicking through the demo. At 11:40 a support ticket lands: a customer bought a $219.00 espresso machine and was charged $3.17 . Then another ticket. Then thirty. By noon someone finds it: the new coupon feature applies the percentage discount once per line item and once more to the order total. Stack a 20% coupon with a gift card, and the discount multiplies. Nobody tested that combination, because "testing" meant a senior dev squinting at the code and saying "looks right." The fix took eleven minutes. The refunds took two weeks. And the uncomfortable lesson is the ratio every experienced engineer eventually internalizes: a bug caught by a unit test costs minutes; the same bug caught by a customer costs days. Unit tests are the cheapest bug-catcher you will ever buy — and in Java, JUnit 5 plus Mockito is the standard-issue k...