Unit test
|
In computer programming, a unit test is a method of testing the correctness of a particular module of source code.
The idea is to write test cases for every non-trivial function or method in the module so that each test case is separate from the others if possible.
Contents |
Benefits
The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. It provides a written contract that the piece must satisfy. This isolated testing provides two main benefits:
- 1. Encourages change
- Unit testing allows the programmer to refactor code at a later date, and make sure the module still works correctly (regression testing). This provides the benefit of encouraging programmers to make changes to the code since it is easy for the programmer to check if the piece is still working properly.
- 2. Simplifies Integration
- Unit testing helps eliminate uncertainty in the pieces themselves and can be used in a bottom-up testing style approach. By testing the parts of a program first and then testing the sum of its parts will make integration testing easier.
Limitations
It is important to realize that unit-testing will not catch every error in the program. By definition, it only tests the functionality of the units themselves. Therefore, it will not catch integration errors, performance problems and any other system-wide issues. In addition, it may not be trivial to anticipate all special cases of input the program unit under study may receive in reality. Unit testing is only effective if it is used in conjunction with other software testing activities.
Applications
Unit testing predates, by far, Extreme Programming.
The unit testing concept is part of the Extreme Programming method of software engineering. Various unit testing frameworks, based on a design by Kent Beck, have come to be known as xUnit testing frameworks and are available for many programming languages and development platforms. Unit testing is the building block to test driven development (TDD). Extreme Programming and most other methods use unit tests to perform black box testing.
Note that the Extreme Programming community has renamed unit tests to "programmer tests".
The D programming language offers direct support for unit testing.
See also
- Extreme Programming
- Regression testing
- Test case
- IEEE 1008, a standard for unit testing
- JUnit - a unit testing module for Java
- JTiger - a feature-rich, open source unit test framework for Java
- PyUnit - a unit testing module for Python
- NUnit - a unit testing module for Microsoft .NET
- SUnit - a unit testing module for Smalltalk
- Test-Unit - a unit testing module for Perl
External links
Framework
- Kent Beck's original testing framework paper (http://www.xprogramming.com/testfram.htm)
- List of various unit testing frameworks (http://www.xprogramming.com/software.htm)
- Community site on unit testing and Test Driven Development (http://www.testdriven.com)
Implementations
- AUnit (http://libre.act-europe.fr/aunit/main.html) - a unit testing framework for Ada programming language
- DUnit (http://dunit.sourceforge.net/) - a unit testing module for Delphi
- ProgTest (http://homepage.mac.com/jon_n_kay/progtest/) - a unit testing framework for Objective-C
- OCUnit (http://www.sente.ch/software/ocunit/) - a unit testing framework for Objective-C
- ObjcUnit (http://oops.se/objcunit/) - JUnit-like unit testing framework for Objective-C
- UnitKit (http://unitkit.org/) - a unit testing framework for Objective-C
- OUnit (http://www.xs4all.nl/~mmzeeman/ocaml) - a unit testing framework for Ocaml
- PHPUnit (http://pear.php.net/package/PHPUnit) - a unit testing framework for PHP
- SimpleTest (http://www.lastcraft.com/simple_test.php) - a unit testing framework for PHP with Mock objects
- Boost Test Library (http://www.boost.org/libs/test/doc/index.html) - a short learning-curve testing framework (including unit testing) for C++
- CPPUnit (http://cppunit.sourceforge.net/cgi-bin/moin.cgi) - a unit testing framework for C++
- TUT (http://tut-framework.sourceforge.net/) - a unit testing framework for C++
- NUnit (http://www.nunit.org/) - a unit testing framework for the .Net programming languages
- csUnit (http://www.csunit.org/) - a unit testing framework for the .Net programming languages
- AS2Unit (http://www.as2unit.org/) - a unit testing framework for ActionScript 2.0
- JUnit (http://www.junit.org/) - a unit testing framework for Java
- JUnitEE (http://www.junitee.org/) - a unit testing framework for J2EE
- DBUnit (http://www.dbunit.org/) - a unit testing framwork for Databases as a JUnit extension
- SUnit (http://sunit.sourceforge.net/) - a unit testing framework for Smalltalk
- FoxUnit (http://www.foxunit.org/) - a unit testing framework for Visual FoxPro
- JTiger (http://www.jtiger.org/) - a feature-rich, open source unit test framework for Javade:Unit-Test