|developer||Erich Gamma , Kent Beck , David Saffe|
( April 10, 2020 )
|Current preliminary version||5.7.0.M1
(April 19, 2020)
|category||Test - Framework|
|License||Common Public License|
JUnit is a framework for testing of Java programs, which particularly for automated unit testing of individual units ( classes or methods is suitable). JUnit was initially developed by Erich Gamma and Kent Beck . It is based on concepts that were originally developed under the name SUnit for small talk .
A JUnit test has only two results: Either the test succeeds (then it is “green”) or it fails (then it is “red”). The failure may be caused by a bug ( error ) or an incorrect result ( failure ) have, both by exception to be signaled. The difference between the two terms is that failures are expected, while errors occur more unexpectedly. Technically be Failures means of a special exception called AssertionFailedError , signaled during all other exceptions from JUnit framework as Error be interpreted.
JUnit in the software development process
A programmer first writes an automatically repeatable (JUnit) test and then the code to be tested . The test is itself a piece of software and is programmed just like the code to be tested. If another programmer wants to change the resulting code at a later point in time, he first calls all JUnit tests to ensure that the code is free of errors before changing it. Then he makes the change and calls the JUnit tests again. If this fails, he knows that he has made a mistake himself and must correct it. This cycle is repeated until all JUnit tests run again without errors.
This procedure is also called " test-driven development " ( English test-driven software development ) and is one of the agile methods . The idea is to create bug-free code by not implementing anything that is not tested. If test cases are only developed after the code, there is a higher probability of overlooking important test cases.
One implementation of JUnit for Java EE is Cactus (formerly J2EEUnit ) from the Jakarta project . Since Java EE 5, so-called out-of-container frameworks ( e.g. EJB3Unit ) have been established that allow tests to be carried out outside of the container.
Extensions to JUnit extend JUnit for use in certain areas ( e.g. HTTPUnit for web development, DBUnit for database development). In addition, there are plugins for development environments that enable or expand the use of JUnit within the development environment ( e.g. Infinitest for continuous testing or DJUnit for calculating code coverage , the tests).
- JUnit 5
- JUnit is now made up of several different modules from three different sub-projects.
- JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
- JUnit 4.0
- In this version the package structure was changed. All classes can now be found in
org.junit.*. The classes from version 3.x are also included, they can still be found under
- JUnit 4.5
- Support for the
assertThatassert statement with the help of the Hamcrest framework.
- JUnit 4.8
- Tests can now be marked with categories. This makes it possible to only run tests of a certain category.
- JUnit 4.9
- ClassRule annotation for defining rules for unit test classes.
- JUnit 4.10
- RuleChain for arranging rules, TemporaryFolder for creating and using temporary files and directories.
- JUnit 4.11
- FixMethodOrder for the sorted execution of the test methods.
- TestNG - alternative to JUnit
- Apache Cactus , HTTPUnit , DBUnit - known extensions to JUnit
- EasyMock , Mockito , PowerMock - JUnit-based mocking frameworks
- List of module test software
- Johannes Link: Software tests with JUnit - techniques of test-driven development . 2., revised. and exp. Edition dpunkt-Verlag, Heidelberg 2005, ISBN 3-89864-325-5 .
- Frank Westphal: Test-driven development with JUnit and FIT . dpunkt, 2005, ISBN 3-89864-220-8 ( frankwestphal.de [PDF; 2.8 MB ]).
- Release 5.6.2 . April 10, 2020 (accessed April 11, 2020).
- Mike Clark: JUnit FAQ. What's the difference between a failure and an error? (No longer available online.) December 28, 2004, archived from the original on December 30, 2004 ; Retrieved on October 25, 2010 (English, applies to JUnit 3. Could have changed!): "Assertions are used to check for the possibility of failures, therefore failures are anticipated. Errors are unanticipated problems resulting in uncaught exceptions being propagated from a JUnit test method. "
- Stefan Bechtold, Sam Brannen, Johannes Link, Matthias Merdes, Marc Philipp, Juliette de Rancourt, Christian Stein: JUnit 5 User Guide. March 21, 2020, accessed on July 29, 2020 .
- Frank Westphal: JUnit 4.0
- JUnit release notes
- Release Notes for JUnit 4.8
- JUnit 4.9 released
- JUnit 4.10 released
- JUnit 4.11 is released