{{Redirect|Junit|the Egyptian goddess|Iunit}}{{Update|reason=this article focuses primarily on JUnit 4 and needs to be updated for JUnit 5|date=June 2018}}{{Infobox software | name = JUnit | logo = | screenshot = | caption = | developer = Kent Beck, Erich Gamma, David Saff, Kris Vasudevan | latest release version = 5.4.1[1] | latest release date = {{release date|2019|03|17}} | operating system = Cross-platform | programming language = Java | genre = Unit testing tool | license = Eclipse Public License[2] (relicensed from CPL before) | website = {{URL|http://junit.org}} }}
JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated with SUnit.
JUnit is linked as a JAR at compile-time; the framework resides under package junit.framework for JUnit 3.8 and earlier, and under package org.junit for JUnit 4 and later.
A research survey performed in 2013 across 10,000 Java projects hosted on GitHub found that JUnit (in a tie with slf4j-api), was the most commonly included external library. Each library was used by 30.7% of projects. [3]
Example of JUnit test fixture
A JUnit test fixture is a Java object. With older versions of JUnit, fixtures had to inherit from junit.framework.TestCase, but the new tests using JUnit 4 should not do this.[4] Test methods must be annotated by the @Test annotation. If the situation requires it,[5] it is also possible to define a method to execute before (or after) each (or all) of the test methods with the @Before (or @After) and @BeforeClass (or @AfterClass) annotations.[4]
Ports
JUnit alternatives have been written in other languages including:
Actionscript (FlexUnit)
Ada (AUnit)
C (CUnit)
C# (NUnit)
C++ (CPPUnit, CxxTest)
Coldfusion (MXUnit)
Delphi (DUnit)
Erlang (EUnit)
Eiffel ([https://docs.eiffel.com/book/eiffelstudio/using-autotest Auto-Test]) - JUnit inspired getest (from Gobosoft), which led to Auto-Test in Eiffel Studio.
Fortran (fUnit, pFUnit)
Free Pascal (FPCUnit)
Golang ([https://github.com/jstemmer/go-junit-report Go JUnit report])
Haskell (HUnit)
JavaScript (JSUnit)
Microsoft .NET (NUnit)
Objective-C (OCUnit)
OCaml (OUnit)
Perl (Test::Class and Test::Unit)
PHP (PHPUnit)
Python (PyUnit and [https://pypi.org/project/junit-xml/ junit-xml])
Qt (QTestLib)
R (RUnit)
Ruby ([https://github.com/sj26/rspec_junit_formatter JUnit for Rspec])
See also
{{Portal|Software Testing|Free and open-source software}}
TestNG, another test framework for Java
Mock object, a technique used during unit testing
Mockito and PowerMock, mocking extensions to JUnit
JUnit-Tools, a set of tools to optimize the creation and maintainability of junit-tests (www.junit-tools.org)
EvoSuite, a tool to automatically generate JUnit tests
[https://github.com/Nordstrom/JUnit-Foundation JUnit Foundation], a set of extensions including event notifications, timeout management, automatic retry, and artifact capture.
References
1. ^[https://github.com/junit-team/junit5/releases JUnit Releases] 2. ^{{cite web | url=https://github.com/junit-team/junit/commit/3171c4b29cb207e71fc2f752f0fbcb235bc8e784 | title=Relicense JUnit from CPL to EPL | publisher=Philippe Marschall | date=18 May 2013 | accessdate=20 September 2013}} 3. ^{{cite web|url=http://www.takipiblog.com/2013/11/20/we-analyzed-30000-github-projects-here-are-the-top-100-libraries-in-java-js-and-ruby/ |title=We Analyzed 30,000 GitHub Projects – Here Are The Top 100 Libraries in Java, JS and Ruby}} 4. ^1 {{cite web| url=http://junit.sourceforge.net/doc/cookbook/cookbook.htm| title=JUnit Cookbook| publisher=junit.sourceforge.net| author=Kent Beck, Erich Gamma| accessdate=2011-05-21}} 5. ^{{cite web| url=http://c2.com/cgi/wiki?ExpensiveSetUpSmell| title=Expensive Setup Smell| publisher=C2 Wiki| author=Kent Beck| accessdate=2011-11-28}}