30

I have some difficulty understanding the concept of "fixture". I know what a test suite is, a test case, a test run, but what exactly is a "fixture"? A parameterized test case?

It seems to me that the meaning or semantics of the term "fixture" can vary slightly by programming language or by testing framework? I think a phpunit fixture

"the code to set the world up in a known state and then return it to its original state when the test is complete. This known state is called the fixture of the test."

is slightly different from a "fitnesse fixture", where

"Fixtures are a bridge between the Wiki pages and the System Under Test (SUT), which is the actual system to test".

Is there an expert in software testing around here who can answer this question? References to other programming languages are welcome.

2
  • 1
    @chris (and knb) please put answers in as answers, not edits to the question.
    – user40980
    Jun 8, 2015 at 16:36
  • glad you asked, i almost ask same question :) Nov 13, 2017 at 11:51

2 Answers 2

27

In the context of testing tools you mentioned, such as PHPUnit and Fitnesse, this term definitely refers to the notion of test fixture:

something used to consistently test some item, device, or piece of software...

Software

Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Some people call this the test context.

Examples of fixtures:

  • Loading a database with a specific, known set of data
  • Erasing a hard disk and installing a known clean operating system installation
  • Copying a specific known set of files
  • Preparation of input data and set-up/creation of fake or mock objects...

Use of fixtures

Some advantages of fixtures include separation of the test initialization (and destruction) from the testing, reusing a known state for more than one test, and special assumption by the testing framework that the fixture set up works...

3
  • 3
    to summarize, a fixture is an object with a known state that tests (or whatever) can proceed with and have expected results. Sep 19, 2013 at 14:20
  • so I'd say a fixture is some kind of abstraction of a test suite. Maybe I was confused because sometimes people use synonymously: the term fixture (the abstraction, or the stateful object at early test-runtime ) and fixture configuration (the configuration saved away to get processed by the setup() methods).
    – knb
    Sep 20, 2013 at 7:10
  • 1
    @davethieben Does it have to be an object? -- I don't think so, although it often is. Jan 6, 2020 at 13:24
7

Outside of the testing context, the term fixture is sometimes used to describe the initial data in storage (like the initial data in a database) when deploying an application for the first time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.