TDD approaches—classic (state-focused) and London (interaction-focused) — explained through Kotlin examples using test doubles like stubs and mocks. By Michal Przysucha.
The article demonstrates classic TDD through a property price calculator test, where the system under test (SUT) interacts with a stubbed collaborator (MarketPricesProvider) to return predefined values. Verification occurs via the SUT’s direct output (e.g., calculated price).
For the London school, the example extends to an orchestrator that generates reports and sends emails. Here, interactions between the orchestrator and its collaborators (calculator, templates, email sender) are verified using mocks, ignoring the final state. The author introduces test doubles: stubs (for indirect inputs), mocks (for interactions), fakes (simplified implementations), and spies (tracking invocations).
Two testing strategies emerge: Inside-Out (bottom-up, classic) and Outside-In (top-down, London), each with trade-offs—e.g., mock fragility vs. classic decoupling.
This article provides a clear, practical comparison of TDD schools using Kotlin examples, demystifying test doubles without framework bias. It’s valuable for developers transitioning between TDD styles but doesn’t introduce novel concepts. Its impact lies in clarifying trade-offs, making it a recommended resource for teams refining their testing strategy. Nice one!
[Read More]