Java Reference
In-Depth Information
7.4.2
Automated testing using JUnit
Support for regression testing is integrated in BlueJ (and many other development environ-
ments) using a testing system called JUnit. JUnit is a testing framework devised by Erich
Gamma and Kent Beck for the Java language, and similar systems are now available for many
other programming languages.
JUnit, www.junit.org JUnit is a popular testing framework to support organized unit testing
and regression testing in Java. It is available independent of specific development environments,
as well as integrated in many environments. JUnit was developed by Erich Gamma and Kent Beck.
You can find the software and a lot of information about it at http://www.junit.org .
To start investigating regression testing with our example, open the online-shop-junit pro-
ject. This project contains the same classes as the previous one, plus an additional class,
SalesItemTest .
SalesItemTest is a test class. The first thing to note is that its appearance is different from
what we have seen previously (Figure 7.2). It is annotated as a <<unit test>> , its color is
different from that of the ordinary classes in the diagram, and it is attached to the SalesItem
class (it will be moved with this class if SalesItem is moved in the diagram).
You will note that Figure 7.2 also shows some additional controls in the main window, below
the Compile button. These allow you to use the built-in regression testing tools. If you have
not used JUnit in BlueJ before, the testing tools are switched off, and the buttons will not yet
be visible on your system. You should switch on these testing tools now. To do this, open the
Miscellaneous tab in your Preferences dialog and ensure that the Show unit testing tools option
is selected.
Figure 7.2
A project with a test
class
 
Search WWH ::




Custom Search