*** Welcome to piglix ***

Test fixture


A test fixture is something used to consistently test some item, device, or piece of software.Test fixtures can be found when testing electronics, software and physical devices.

In testing electronic equipment such as circuit boards, electronic components, and chips, a test fixture is a device or setup designed to hold the device under test in place and allow it to be tested by being subjected to controlled electronic test signals.

Examples are a bed of nails tester or SmartFixture.

A software test fixture sets up the system for the testing process by providing it with all the necessary code to initialize it, thereby satisfying whatever preconditions there may be. An example could be loading up a database with known parameters from a customer site before running your test. The Ruby on Rails web framework uses YAML to initialize a database before running a test. This allows for tests to be repeatable, which is one of the key features of an effective test framework.

Test fixtures can be set up in three ways: in-line setup, delegate setup, and implicit setup. In-line setup is where the developer creates the test fixture in the same method as the rest of the test and is the simplest test fixture to create but can lead to duplication if multiple tests need to use the same initial data. Delegate setup is where the developer places the test fixture in a separate standalone helper method that can be accessed by multiple test methods. Implicit setup is where the developer places the test fixture in a setup method which is used to setup multiple test methods. This is different from delegate setup in that the overall setup of multiple tests are in a single setup method where the test fixture gets created instead of each test method having its own setup procedures and linking to an external test fixture.

The advantage of a test fixture is that it allows for tests to be repeatable since you are always starting with the same setup every time. Test fixtures also eases test code design by allowing the developer to separate methods into different functions and reuse each function for other tests. It also preconfigures tests into a known state at start instead of working with whatever was left from a previous test run. A disadvantage would be that it could lead to duplication of test fixtures if using in-line setup.

It is considered bad practice when test fixtures are too general in implicit setup, or when the test method sets up a test fixture and does not use it during the test. A more subtle issue is if the test methods ignore certain fields within the test fixture. Another bad practice would be a test setup that contains more steps than are needed for the test; this is a problem seen in in-line setup.


...
Wikipedia

...