Chapter 22. Finishing âMy Listsâ: Outside-In TDD
In this chapter Iâd like to talk about a technique called Outside-In TDD. Itâs pretty much what weâve been doing all along. Our âdouble-loopâ TDD process, in which we write the functional test first and then the unit tests, is already a manifestation of outside-inâwe design the system from the outside, and build up our code in layers. Now Iâll make it explicit, and talk about some of the common issues involved.
The Alternative: âInside-Outâ
The alternative to âoutside-inâ is to work âinside-outâ, which is the way most people intuitively work before they encounter TDD. After coming up with a design, the natural inclination is sometimes to implement it starting with the innermost, lowest-level components first.
For example, when faced with our current problem, providing users with a
âMy Listsâ page of saved lists, the temptation is to start by adding an âownerâ
attribute to the List
model object, reasoning that an attribute like this is
âobviouslyâ going to be required. Once thatâs in place, we would modify the
more peripheral layers of code, such as views and templates, taking advantage
of the new attribute, and then finally add URL routing to point to the new
view.
It feels comfortable because it means youâre never working on a bit of code that is dependent on something that hasnât yet been implemented. Each bit of work on the inside is a solid foundation on which to build the next ...
Get Test-Driven Development with Python, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.