![Show Menu](styles/mobile-menu.png)
![Page Background](./../common/page-substrates/page0365.png)
CHAPTER 19
Test Isolation, and “Listening to Your Tests”
In the last chapter, we made the decision to leave a unit test failing in the views layer
while we proceeded to write more tests and more code at the models layer to get it to
pass.
We got away with it because our app was simple, but I should stress that, in a more
complex application, this would be a dangerous decision. Proceeding to work on lower
levels while you’re not sure that the higher levels are
really
finished or not is a risky
strategy.
I’m grateful to Gary Bernhardt, who took a look at an early draft of
the previous chapter, and encouraged me to get into a longer discus‐
sion of test isolation.
Ensuring isolation between layers does involve more effort (and more of the dreaded
mocks!), but it can also help to drive out improved design, as we’ll see in this chapter.
Revisiting Our Decision Point: The Views Layer Depends on
Unwritten Models Code
Let’s revisit the point we were at half-way through the last chapter, when we couldn’t get
the
new_list
view to work because lists didn’t have the
.owner
attribute yet.
We’ll actually go back in time and check out the old codebase, so that we can see how
things would have worked if we’d used more isolated tests.
$
git checkout -b more-isolation
# a branch for this experiment
$
git reset --hard revisit_this_point_with_isolated_tests
Here’s what our failing tests looks like:
337