Test fixture

From Wikipedia, the free encyclopedia

This article is about the programming concept. For other uses, see Fixture (disambiguation).

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 setup/creation of fake or mock objects

Contents

[edit] Test fixture in xUnit

In generic xUnit a test fixture is all the things we need to have in place in order to run a test and expect a particular outcome.

Frequently fixtures are created by handling setUp() and tearDown() events of the unit testing framework. In setUp() one would create the expected state for the test, and in tearDown() it would clean up what had been set up.

Four phases of a test:

  1. Set up -- Setting up the test fixture.
  2. Exercise -- Interact with the system under test.
  3. Verify -- Determine whether the expected outcome has been obtained.
  4. Tear down -- Tear down the test fixture to return to the original state.

[edit] 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.

[edit] See also

[edit] References