The Four-Phase Test
Well-structured tests often follow a specific ordering of work:
- Setup
- Exercise
- Verify
- Teardown
Setup
Test setup may include object or state instantiation, including initializing variables, persisting data to the database, or writing files to disk.
Exercise
With state in place, the test will then exercise the system under test by executing necessary behavior of the particular area of the code.
Verify
In the verify step, we then make assertions against the outcome of the behavior exercised to ensure the results are expected.
Teardown
During the teardown step, we clean up any global state (e.g. rolling back database transactions or cleaning up created files) and un-mock any objects.