Jump to content

Test fixture: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Eubot (talk | contribs)
Hatnote formatting, see User:Eubot/Hatnote formatting
Line 9: Line 9:


== Test fixture in xUnit ==
== 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.
In generic [[xUnit]], a ''test fixture'' is all the things that must be 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 [[List of unit testing frameworks|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.
Frequently fixtures are created by handling ''setUp()'' and ''tearDown()'' events of the [[List of unit testing frameworks|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.

Revision as of 15:54, 29 July 2008

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

Test fixture in xUnit

In generic xUnit, a test fixture is all the things that must be 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.

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.

See also

References