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.

knb
  • 747
  • 1
  • 8
  • 16

2 Answers2

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...

gnat
  • 21,442
  • 29
  • 112
  • 288
  • 3
    to summarize, a fixture is an object with a *known state* that tests (or whatever) can proceed with and have expected results. – dave thieben Sep 19 '13 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 '13 at 07:10
  • 1
    @davethieben Does it **have to be** an object? -- I don't think so, although it often is. – Sebastian Nielsen Jan 06 '20 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.

Chris
  • 105
  • 4
Pavels
  • 347
  • 1
  • 3