Write Tests Backwards
Although we stick to a canonical format for test code, we don’t necessarily write
tests from top to bottom. What we often do is: write the test name, which helps us
decide what we want to achieve; write the call to the target code, which is the entry
point for the feature; write the expectations and assertions, so we know what effects
the feature should have; and, write the setup and teardown to define the context
for the test. Of course, there may be some blurring of these steps to help the
compiler, but this sequence reflects how we tend to think through a new unit test.
Then we run it and watch it fail.