What are fixtures in programming?

Matjaz Muhic picture Matjaz Muhic · Aug 22, 2012 · Viewed 71.7k times · Source

I have heard of this term many times (in the context of programming) but couldn't find any explanation of what it meant. Any good articles or explanations?

Answer

m01 picture m01 · Feb 4, 2013

I think you're referring to test fixtures:

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

(source: wikipedia, see link above)

Here are also some practical examples from the documentation of the 'Google Test' framework.