Jump to content

JUnit: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
refs before EL per wiki style
VOGELLA (talk | contribs)
Line 69: Line 69:
* [http://www.junitdoclet.org/ JUnitDoclet - Test Suite Generator for JUnit-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]
* [http://merobase.com merobase - the first code search engine worldwide that supports JUnit test cases for test-driven component retrieval]
* [http://www.vogella.de/articles/JUnit/article.html JUnit 4.x with Eclipse]


[[Category:Java platform]]
[[Category:Java platform]]

Revision as of 05:36, 21 December 2007

JUnit
Developer(s)Kent Beck, Erich Gamma, David Saff
Stable release
4.4 / July 18, 2007
Repository
Operating systemCross-platform
TypeTest Tool
LicenseCommon Public License
Websitejunit.org

JUnit is a unit testing framework for the Java programming language. Created by Kent Beck and Erich Gamma, JUnit is one of, and arguably the most successful of, the xUnit family of frameworks that originated with Kent Beck's SUnit. JUnit has spawned its own ecosystem of JUnit extensions. "junit" is also used as a synonym for unit tests as in, "Did you run the junits [pronounced jay-you-nits] before you checked in?"

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, for example in the book Test-Driven Development: By Example, ISBN 0-321-14653-0 by Kent Beck.

JUnit has been ported to other languages, including PHP (PHPUnit), C# (NUnit), Python (PyUnit), Fortran (fUnit), Perl (Test::Class and Test::Unit) and C++ (CPPUnit). This family of unit testing frameworks is referred to collectively as xUnit. TestNG has many of the same goals as JUnit.

And more recently, owing to the development of rich client frameworks such as AJAX, a port of JUnit has been developed for JavaScript (JSUnit) http://www.jsunit.net/.

"Hello world" example in JUnit 3.8 and earlier:

 public class HelloWorld extends TestCase
 {
   public void testMultiplication()
   {
     // Testing if 3*2=6:
     assertEquals ("Multiplication", 6, 3*2);
   }
 }

(compare with the similar example for Mauve.)

The method testMultiplication will be discovered automatically by reflection.

"Hello world" example in JUnit 4.0:

 public class HelloWorld
 {
   @Test public void testMultiplication()
   {
     // Testing if 3*2=6:
     assertEquals ("Multiplication", 6, 3*2);
   }
 }

The method testMultiplication will be discovered automatically by its Test Annotation (a feature of Java 5).

References

  • "JUnit in Action". ISBN 1-930110-99-5.
  • Kent Beck. "JUnit Pocket Guide". O'Reilly, 2004. ISBN 0-596-00743-4.
  • J. B. Rainsberger. "JUnit Recipes". Manning, 2004. ISBN 1932394230.