JUnit

JUnit is a framework for testing of Java programs, especially for the automated unit testing of individual units ( classes or methods ) is appropriate. It is based on concepts that were originally developed under the name SUnit for Smalltalk.

Meanwhile, there are JUnit -like frameworks for many other programming languages. Often these programs are grouped under the name xUnit.

Main developer of the JUnit framework are Erich Gamma and Kent Beck.

Operation

A JUnit test has only two results: either the test succeeds ( then he is "green") or it fails (then it is "red"). The failure may be caused by an error ( Error) or a false result ( failure) have, both of which are signaled by exception. The difference between the two terms is that failures are expected, while errors occur rather unexpectedly. Technically Failures are signaled by a special exception called " AssertionFailedError ", while all other exceptions are interpreted by the JUnit framework as an error.

JUnit in the software development process

JUnit is an important tool in the Extreme Programming and support in this context, the idea of ​​Extreme Testing.

Method

In this case, a programmer first writes an automatically repeatable ( JUnit ) test and then the code under test. The test itself is a piece of software and, like the code under test programmed. If another programmer wants to modify the code so incurred at a later date, he first calls all JUnit tests to verify that the code is free of errors before it was amended. Then he performs the change and calls the JUnit tests on again. Failure of this, he knows that he has installed is faulty, and must correct it. This cycle is repeated until all the JUnit tests " green " are again.

This method is also called "Test Driven Development " (English Test-driven software development ) and is one of the agile methods. The idea is to produce low-error code by nothing is implemented, which is not tested. If test cases developed after the code, the more likely to overlook important test cases.

JUnit extensions

An implementation of JUnit for Java EE is Cactus (formerly J2EEUnit ) from the Jakarta project. Since JEE 5, so-called out-of- container frameworks have been established (for example EJB3Unit ) that permit execution of tests outside the container.

Extensions to extend JUnit JUnit for use in certain areas ( for example, HttpUnit for web development, DBUnit for database development). In addition, there are some plugins for development environments, enabling the use of JUnit within the development environment or expand ( for example Infinitest for continuous testing or DJUnit for calculating the code coverage, engl. "Code Coverage", the tests).

Revision history

457515
de