xUnit

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Various code-driven testing frameworks have come to be known collectively as xUnit. These frameworks allow testing of different elements (units) of software, such as functions and classes. The main advantage of xUnit frameworks is that they provide an automated solution with no need to write the same tests many times, and no need to remember what should be the result of each test. Such frameworks are based on a design by Kent Beck, originally implemented for Smalltalk as SUnit, but are now available for many programming languages and development platforms.

Contents

[edit] xUnit Design

The overall design of xUnit frameworks depends on several components.

[edit] Test Fixtures

A test fixture is the set of preconditions or state needed for a test to succeed. Also known as a test context. The developer should set up a known good state before the tests, and after the tests return to the original state.

[edit] Test Suites

A test suite is a set of tests that all share the same fixture. The order of the test shouldn't matter.

[edit] Test Execution

The execution of an individual unit test proceeds as follows:

setup(); /* First, we should prepare our 'world' to make an isolated environment for testing */
...
/* Body of test - Here we make all the tests */
...
teardown(); /* In the end, whether succeed or fail we should clean up our 'world' to not disturb other tests or code */

The setup() and teardown() methods serve to initialize and clean up test fixtures.

[edit] Assertions

An assertion is a function or macro that verifies the behavior (or the state) of the unit under test. Failure of an assertion typically throws an exception, aborting the execution of the current test.

[edit] See also

Unit testing in general:

Programming approach to unit testing:

[edit] External links

Personal tools