Extracting an action helper
This section covers the use of a helper to simplify the Act phase of a test.
Understanding the Arrange-Act-Assert pattern
The Arrange-Act-Assert pattern is a standard way to describe the order in which unit tests are written.
They start with the Arrange phase, which is when the structure under test is primed for work. Any input data is constructed, and any preparatory methods are called that get the system into the right state.
Then, we have the Act phase, which invokes the operation that is being checked. Finally, the test ends with the Assert phase, which can be one or more expectations (or assertions) that verify that the operation did what it was meant to.
Each of these three phases benefits from different strategies to remove duplication.
The Act phase is the one that I think benefits least from the removal of duplication. That’s because the majority of unit tests you’ll write – and all the unit tests in this book...