Well-written unit tests follow a clean and consistent structure based on four exactly defined phases. In this section, we will learn about the purpose of each of those and delve into some subtleties of fixture setup and result verification.
"A tidy house, a tidy mind." | ||
--Old adage |
The attentive reader may have wondered why our first test setFetchCount
was segmented by the use of empty lines. To answer this question, let's have an in-depth look at each of these segments with the first listing of this section, showing the common structure of a unit test. There are minor refactorings and additional comments compared to the version in the last chapter to emphasize more on the separation.