- JUnit
Infobox Software
name = JUnit
caption =
developer =Kent Beck ,Erich Gamma , David Saff
latest release version = 4.5
latest release date = release date|2008|08|08
operating system =Cross-platform
programming language = Java
genre =Unit testing tool
license =Common Public License
website = http://junit.orgJUnit is a unit testing framework for the Java programming language. Created by
Kent Beck andErich Gamma , JUnit is one of thexUnit family of frameworks that originated with Kent Beck'sSUnit . JUnit has spawned its own ecosystem of [http://www.junit.org/news/extension/index.htm JUnit extensions] .Experience gained with JUnit has been important in the development of
test-driven development , and as a result, some knowledge of JUnit is often presumed in discussions of test-driven development.JUnit has been ported to other languages, including
PHP (PHPUnit ), C# (NUnit ), Python (PyUnit ), Fortran (fUnit ),Perl ( [http://search.cpan.org/~adie/Test-Class-0.24/lib/Test/Class.pm Test::Class] and [http://search.cpan.org/~mcast/Test-Unit-0.25/lib/Test/Unit.pm Test::Unit] ),C++ (CPPUnit ) and JavaScript (JSUnit ) . This family of unit testing frameworks is referred to collectively asxUnit .TestNG has many of the same goals as JUnit.Examples
JUnit 3.8
A simple "Hello world" example in JUnit 3.8 and earlier:
(compare with the similar example for Mauve.)
The method
testMultiplication
will be discovered automatically by reflection.JUnit 4.0
Translating this above "Hello world" example into JUnit 4.0 results in:The method
testMultiplication
will be discovered automatically by its Test Annotation (a feature of Java 5). It offers a fundamental test using only the framework and the core of the Java virtual machine and language specifications.But there are several issues to consider here: JUnit is not a programming language, so this trivial example does not demonstrate the power of JUnit. It is conventional to see test case class names end with "Test", as well as the prefix name specified as the name of the class being tested. Also, something more meaningful is usually printed in the assertion message. The unit test subclasses the base class TestCase as in the following example:
External links
* [http://junit.org/ JUnit home page]
* [http://www.linux.ie/articles/tutorials/junit.php Unit tests with JUnit]
* [http://www.ibm.com/developerworks/opensource/library/os-junit/?ca=dgr-lnxw07JUnite JUnit antipatterns (developerWorks)] and [http://www.exubero.com/junit/antipatterns.html JUnit antipatterns (Exubero)]
* [http://www.ibm.com/developerworks/java/library/j-junit4.html?ca=dgr-lnxw01JUnit4 An early look at JUnit 4]
* [http://www.devx.com/Java/Article/31983 Get Acquainted with the New Advanced Features of JUnit 4]
* [http://www.junitfactory.com JUnitFactory - Free web-based generation of JUnit characterization tests]
* [http://www.junitdoclet.org/ JUnitDoclet - Test Suite Generator for JUnit-Tests]
* [http://merobase.com merobase - the first code search engine worldwide that supports JUnit test cases for test-driven component retrieval]
Wikimedia Foundation. 2010.