A test fixture is a group of objects that are in a fixed state and are used as a baseline for executing tests. Their goal is to guarantee that tests are conducted in a consistent and well-known environment, resulting in reproducible findings.
Fixtures that are examples include:
- Using a specific, well-known collection of data to populate a database
- Copying a collection of files that are well-known.
- Setup/creation of false or mock objects, as well as preparation of incoming data
If a collection of tests uses the same fixtures, you should build the common test fixture using a separate setup code. You can add code inside the test function to generate its own test fixture if a set of tests requires distinct test fixtures.