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 Test-driven development (TDD) is a software development process relying on software requirements being converted to test cases before software is fully developed, and tracking all software development by repeatedly testing the software against al ...
, 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 xUnit is the collective name for several unit testing frameworks that derive their structure and functionality from Smalltalk's SUnit. ''SUnit'', designed by Kent Beck in 1998, was written in a highly structured object-oriented style, which len ...
that originated with SUnit. JUnit is linked as a
JAR A jar is a rigid, cylindrical or slightly conical container, typically made of glass, ceramic, or plastic, with a wide mouth or opening that can be closed with a lid, screw cap, lug cap, cork stopper, roll-on cap, crimp-on cap, press-on c ...
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 MAVEN is an American spacecraft orbiting Mars to study the loss of its atmospheric gases to space, providing insight into the history of the planet's climate and water. The spacecraft name is an acronym for "Mars Atmosphere and Volatile Evolu ...
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 xUnit is the collective name for several unit testing frameworks that derive their structure and functionality from Smalltalk's SUnit. ''SUnit'', designed by Kent Beck in 1998, was written in a highly structured object-oriented style, which len ...
, the family name given to testing frameworks including ''JUnit'' * SUnit, 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 ori ...
based on which JUnit was written *
TestNG TestNG is a testing framework for the Java programming language created by Cédric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., wit ...
, another test framework for Java *
Mock object In object-oriented programming, mock objects are simulated objects that mimic the behaviour of real objects in controlled ways, most often as part of a software testing initiative. A programmer typically creates a mock object to test the behaviou ...
, a technique used during unit testing *
Mockito Mockito is an open source testing framework for Java released under the MIT License. The framework allows the creation of test double objects ( mock objects) in automated unit tests for the purpose of test-driven development (TDD) or behavior- ...
, a mocking library to assist in writing tests *
EvoSuite EvoSuite is a tool that automatically generates unit tests for Java software. EvoSuite uses an evolutionary algorithm to generate JUnit tests. EvoSuite can be run from the command line, and it also has plugins to integrate it in Maven, Intelli ...
, 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