Creating Database Fixtures

Learn how to insert data before running tests.

Let’s make our home page tests more interesting by using database fixtures.

End-to-end test examples with database fixtures

When testing our applications, we cannot only rely on the user interface to make certain test scenarios possible. Often, we have to use fixtures to insert certain data into the database before we run our tests. When doing this, it is important to reset our database in between the tests before running each test. That way, we don’t accidentally have any leftover data in the database from previous tests that might interfere with our results.

In the tests below, we insert a meetup into the database where its start date is in the future and assert that it shows up on the UI. On the other test, we insert a meetup whose start date is in the past and assert that it doesn’t appear on the UI.

Get hands-on with 1200+ tech skills courses.