The next important concept is that of fixtures. Fixtures are pieces of code which run before and/or after every test method. Fixtures serve two main purposes:
- Set-up fixtures ensure that the test environment is in an expected state before a test is run.
- Tear-down fixtures clean up the environment after a test has been run, generally by freeing up resources.
For example, a set-up fixture might create a specific entry in a database prior to running a test. Similarly, a tear-down fixture might remove database entries created by a test. Fixtures are not required for tests, but they are very common, and they are often critical for making tests repeatable.