Fakes Don't Ship
Easy About 15 min Katabench Pro
A test stub lives in the core and the checkout quietly falls back to it when nobody injects a gateway. Evict the stub to the testing namespace and make the dependency mandatory; a convenient default is a production code path.
The full brief is part of Katabench Pro
Pro opens this kata's brief, its starter code and its grader. To see how the track works first, try Config Is Infrastructure, which is free.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
What it practices
- Dependency injection
- Ask for collaborators through constructors instead of newing them up or locating them.
- Test doubles
- Use fakes, stubs and recording collaborators to isolate and observe a unit.
Related katas
- New Is Glue Easy Pro The port exists, the adapter implements it, and the core news the concrete anyway. One
newin the wrong place welds the core to infrastructure; hand the wiring to the composition root. - The Clock Is a Dependency Easy Pro A hotel's cancellation rule and its receipts both read a static infrastructure clock, so the core depends outward and nobody can choose the date it runs against. Hand the core a clock through its constructor and the domain a plain date, so a service that runs for days still dates every cancellation correctly.
- Ask for the Interface Easy Free An order notifier news up its own SmtpEmailer and types the field as the concrete class, even though an IMessenger abstraction sits right next to it. Make the notifier ask for the interface in its constructor. Typing the field as IMessenger while still newing the concrete inside is not the fix.
- Test the Checkout Service Medium Free You're given a correct checkout service with three collaborators. Write recording fakes that prove what it does to each one, and in what order.