xUnit
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. Erich Gamma and Kent Beck ported SUnit to Java, creating JUnit. From there, the framework was also ported to other languages, e.g., CppUnit (for C++), NUnit (for .NET). They are all referred to as xUnit and are usually free, open source software. They are now available for many programming languages and development platforms.
Contents |
[edit] xUnit architecture
All xUnit frameworks share the following basic component architecture, with some varied implementation details.
[edit] Test case
This is the most elemental class. All unit tests are inherited from here.
[edit] Test fixtures
A test fixture (also known as a test context) is the set of preconditions or state needed to run a test. The developer should set up a known good state before the tests, and return to the original state after the tests.
[edit] Test suites
A test suite is a set of tests that all share the same fixture. The order of the tests 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] xUnit frameworks
Many xUnit frameworks exist for various programming languages and development platforms.
[edit] xUnit extensions
Extensions are available to extend xUnit frameworks with additional specialized functionality. Examples of such extensions include XMLUnit, XmlUnit.Xunit, DbUnit, HtmlUnit and HttpUnit.
[edit] See also
Unit testing in general:
Programming approach to unit testing:
[edit] External links
- Kent Beck's original testing framework paper
- Other list of various unit testing frameworks
- OpenSourceTesting.org lists many unit testing frameworks, performance testing tools and other tools programmers/developers may find useful
- Test automation patterns for writing tests/specs in xUnit.
- Martin Fowler on the background of xUnit.
| This computer science article is a stub. You can help Wikipedia by expanding it. |