This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.
By Dagang Wei
What problem in the code below makes the test hard to follow?
The problem is that there is a lot of noise in the account creation code, which makes it hard to tell which details are relevant to the assert statement.
But going from one extreme to the other can also make the test hard to follow:
Now the problem is that critical details are hidden in the _create_account() helper function, so it’s not obvious where the BALANCE field comes from. In order to understand the test, you need to switch context by diving into the helper function.
A good test should include only details relevant to the test, while hiding noise:
By following this advice, it should be easy to see the flow of data throughout a test. For example: