JUnit
   HOME

TheInfoList



OR:

JUnit is a
unit testing In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures&md ...
framework A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of. Framework may refer to: Computing * Application framework, used to implement the structure of an application for an op ...
for the
Java programming language Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run anywh ...
. JUnit has been important in the development of test-driven development, and is one of a family of
unit testing In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures&md ...
frameworks which is collectively known as xUnit that originated with
SUnit SUnit is a unit testing framework for the programming language Smalltalk. It is the original source of the xUnit design, originally written by one of the creators of Extreme Programming, Kent Beck Kent Beck (born 1961) is an American software en ...
. JUnit is linked as a JAR at compile-time. The latest version of the framework, JUnit 5, resides under package org.junit.jupiter. Previous versions JUnit 4 and JUnit 3 were under packages org.junit and junit.framework, respectively. 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.


Example of a JUnit test fixture

A JUnit
test fixture A test fixture is an environment used to consistently test some item, device, or piece of software. Test fixtures can be found when testing electronics, software and physical devices. Electronics In testing electronic equipment such as circuit ...
is a Java object. Test methods must be annotated by the @Test
annotation An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented in the margin of book pages. For anno ...
. If the situation requires it, it is also possible to define a method to execute before (or after) each (or all) of the test methods with the @BeforeEach (or @AfterEach) and @BeforeAll (or @AfterAll) annotations. import org.junit.jupiter.api.*; public class FoobarTest


Previous versions of JUnit

According to Martin Fowler, one of the early adopters of JUnit: As a side effect of its wide use, previous versions of JUnit remain popular, with JUnit 4 having over 100,000 usages by other software components on the Maven Central repository. In JUnit 4, the annotations for test execution callbacks were @BeforeClass, @Before, @After, and @AfterClass, as opposed to JUnit 5's @BeforeAll, @BeforeEach, @AfterEach, and @AfterAll. In JUnit 3, test fixtures had to inherit from junit.framework.TestCase. Additionally, test methods had to be prefixed with 'test'.


See also

* xUnit, the family name given to testing frameworks including ''JUnit'' *
SUnit SUnit is a unit testing framework for the programming language Smalltalk. It is the original source of the xUnit design, originally written by one of the creators of Extreme Programming, Kent Beck Kent Beck (born 1961) is an American software en ...
, the original Smalltalk version written by
Kent Beck Kent Beck (born 1961) is an American software engineer and the creator of extreme programming, a software development methodology that eschews rigid formal specification for a collaborative and iterative design process. Beck was one of the 17 ...
based on which JUnit was written * TestNG, another test framework for Java * Mock object, a technique used during unit testing * Mockito, a mocking library to assist in writing tests * EvoSuite, a tool to automatically generate JUnit tests * List of Java Frameworks


References


External links

* * * {{cite web , url= http://memorynotfound.com/category/testing/junit , title= JUnit , series= Tutorials , website= Memory Not Found , url-status= live , archive-date= Jan 28, 2015 , archive-url= https://web.archive.org/web/20150128114403/http://memorynotfound.com/category/testing/junit Cross-platform software Extreme programming Free software programmed in Java (programming language) Java development tools Java platform Unit testing frameworks Software using the Eclipse license Articles with example Java code