DD Dialogue: London School vs Chicago School
December 27, 2021
Blog > Quality, TDD, Unit Testing | Valentina Cupać
TDD Dialogue: London School vs Chicago School.
Do you find contradictions when reading about TDD? People can’t agree on what’s a unit test?
A unit test:
- Verifies a unit (What’s a unit?)
- Verifies it in isolation (What’s isolation?)
- Verifies it quickly
1. What’s a unit?
Chicago School: A “unit” is a BEHAVIOR. We don’t actually care about what’s the code structure, since that’s an implementation detail.
London School: A “unit” is a STRUCTURE, the smallest unit of code. In OOP, it’s a class (and the public methods inside that class).
2. What’s isolation?
Chicago School: “Isolation” means that the tests need to run in isolation. We mock ONLY the shared dependencies (like database, filesystem, network), but we don’t mock other collaborators. Minimal mocking.
London School: “Isolation” means we test the class in pure isolation, so we mock ALL its collaborators. Extensive mocking.
4. What are integration tests?
Chicago School: An integration test is when we’re integrating with real instances of the shared dependencies.
London School: As soon as we use real instances of collaborators, it’s an integration test.
5. What happens when we refactor?
Chicago School: Because we’re testing behavior (and not the underlying structure), it means that changing the structure will not cause unit tests to break. In fact, refactoring is really easy and convenient!
London School: It depends – is the refactoring an internal change inside the implementation of a method, or are we doing restructuring? If there are no structure changes, then no impact. But if there are structural changes (adding class, removing class, changing public signatures) then several unit tests will fail, so yes, we have to fix them.
7. Where can I read more?
Chicago School: Kent Beck, Uncle Bob, Martin Fowler. See the book “Test-Driven Development by Example” (Kent Beck).
London School: Steve Freeman and Nat Price. See the book “Growing object oriented software guided by tests” (Steve Freeman and Nat Price).
8. What are the highlights?
Chicago School: Units of behavior. We keep everyone focused on business requirements, rather than the code structure. Our greatest strength is that we enable refactoring whilst keeping test suite maintenance low cost. Tests are coupled to the API, the external behavior, so we can easily change the internal structure.
London School: Units of structure. We enable unit testing to be really granular, to test large graphs of interconnected classes in isolation. Tests are focused on classes and their collaboration.
PERSONAL OPINION
I personally lean more towards Chicago-style, because coupling tests to external behavior enables more robust tests – stability when we refactor.
FURTHER READING
Synonyms:
- Chicago school – Detroit / Classical / Inside Out / Bottom-Up
- London school – Mockist / Outside In / Top-Down
Formal overview: https://lnkd.in/dN9_bwvf