JUnit

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.org

JUnit is a unit testing framework for the Java programming language. Created by Kent Beck and Erich Gamma, JUnit is one of the xUnit family of frameworks that originated with Kent Beck's SUnit. 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 as xUnit. TestNG has many of the same goals as JUnit.

Examples

JUnit 3.8

A simple "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.

JUnit 4.0

Translating this above "Hello world" example into JUnit 4.0 results in: public class HelloWorld { @Test public void testMultiplication() { // Testing if 3*2=6: Assert.assertEquals ("Multiplication", 6, 3*2); } }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: public class MultiplierTest extends TestCase { public void testMultiplication() { // Testing if the Multiplier class agrees that, 2*2=4: assertEquals ("Multiplication basic test case 2*2", 4, Multiplier.multiply (2, 2) ); } }

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.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • JUnit — Entwickler u.a. Kent Beck und Erich Gamma Aktuelle Version 4.10 (5. Oktober 2011) Betriebssystem Plattformübergreifend Programmier­sprache …   Deutsch Wikipedia

  • JUnit — Тип Инструмент тестирования Разработчик Кент Бек, Эрик Гамма Операционная система Cross platform Последняя версия 4.11 (14 ноября 2012) Лицензия Common Public License …   Википедия

  • JUnit — Desarrollador Kent Beck, Erich Gamma, David Saff http://junit.sourceforge.net Información general Última versión estable …   Wikipedia Español

  • JUnit — est une bibliothèque de test unitaire pour le langage de programmation Java. Créé par Kent Beck et Erich Gamma, JUnit est certainement le projet de la série des xUnit connaissant le plus de succès. JUnit définit deux types de fichiers de tests.… …   Wikipédia en Français

  • JUnit — es un conjunto de librerías creadas por Erich Gamma y Kent Beck que son utilizadas en programación para hacer pruebas unitarias de aplicaciones Java. JUnit es un conjunto de clases (framework) que permite realizar la ejecución de clases Java de… …   Enciclopedia Universal

  • junit — junít, ă, adj. (reg., înv.) care a rămas june necăsătorit. Trimis de blaurb, 28.06.2006. Sursa: DAR …   Dicționar Român

  • Junit — Iunit (auch Junit) steht als Begriff für: Iunit (Armant), altägyptische Göttin aus Armant Iunit (Heliopolis), altägyptische Göttin aus Heliopolis JUnit, Java Test Framework …   Deutsch Wikipedia

  • Junit (goddess) — In Egyptian mythology, Junit was a minor goddess, whose name means (female one who) was brought . She is associated with Menthu …   Wikipedia

  • Junit — …   Википедия

  • Сравнение каркасов веб-приложений — Это сравнительная таблица фреймворков веб приложений. Содержание 1 Фреймворки 1.1 ASP.NET 1.2 C++ 1.3 ColdFusion Markup Language (CFML) …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”