Home

WTF is a Fixture?

A quick introduction what fixtures are in software, along with other purposes they can serve.

In software engineering, a test fixture, often shortened to fixture, is a mechanism for putting code in a fixed state so it can be more easily tested. Fixtures enable tests to focus on the specific thing being tested, rather that needing to worry about setting up and tearing down before and after the test is run.

For example, consider if we wanted to test what happens when a user clicks on a button on one page, and also what happens when a user fills out a form on another page. Before the tests run, we'd create a user from known (or random) data. Then we can make that user — the fixture — be the subject of our tests.

Fixtures don't have to be used just for testing. In fact, I often use them more outside of testing. Fixtures can also serve as the basis for predictable (fixed) data to use during the development process. For example, in a Ruby on Rails project, I'd use that same method of creating a user for a test as I would to create the user as I'm building out the application. Or in a Gatsby project, I might use a fixture to represent properties sent to a component before the data source is available.

Fixtures can have many uses. Their purpose is simply to provide a set of fixed data — to stabilize the state of the application — so we can stay focused on the work at hand, whether that be writing a test or styling a button.

If you'd like to learn more about fixtures, Wikipedia has a good entry on the subject.

Let's Connect

Keep Reading

WTF is a Headless CMS

The headless CMS is a core tenet of the Jamstack approach, a gamechanging approach to building modern websites. Here is an intro to the headless CMS approach.

Mar 26, 2020

WTF is a Static API

Most APIs today are dynamic. But the Jamstack has provided a path for creating static APIs, which can be incredibly powerful and beneficial in the right scenario.

Mar 30, 2020

WTF is a Monorepo?

Have you heard this term thrown around but not really sure what it means. Well, let's take a quick introductory look at it.

Mar 09, 2021