Introducing test fixtures
In software development, test fixtures (fixtures) is a term used to describe any test data that lives outside of that particular test, and is used to set the application to a known fixed state. Fixtures allow us to have a constant to compare individual test runs against.
Fixtures work best in any environment that is high on the accessibility scale. If we are testing on the localhost or in the CI environment, we can start with a completely empty test database and fill it up with fixture data. When the tests are ready to run, the tests will know the exact state of the application, how many registered users we have, prices of every product, and so on. Let's take a look at a sample fixture, which was used to create a product on our website:
A script parsed the YAML fixture file and then inserted the YAML data into the website's database. As you can see, our fixtures are really simple and easy to read. This is a great advantage of using the YAML format for data, because...