< Zurück | Inhalt | Weiter >

13.4.1 Downloading and Unzipping

Point your browser at the site http://www.junit.org/ (Figure 13.1). From the main page, choose the Download heading.

That takes you to a SourceForge site (Figure 13.2); click on one of the sites near you, though any will do. The download is only a few hundred kilobytes, so it shouldn’t take long.

image

You’ll be left with a file named junitX.Y.Z.zip, where the X, Y, Z char- acters are the digits that tell you what release of JUnit this is. Our examples show the 3.8.1 release.



NOTE

It’s a good idea to inspect the ZIP files that you download before you actually unzip them. We like to know what files and especially what directories are going to get modified or cluttered up by the unzipping. Some ZIP files come with all their files inside of a single folder. Those are fine to unzip in place. Other ZIP files have been built from lots of pieces and unzipping them can make a mess of your current directory, or worse, of other directories that you may not even know about. Instead, play it safe and look before you leap. You can see the list of all the files in the JUnit ZIP file by typing this command:


$ unzip -l junit3.8.1.zip


The -l option will produce a listing of the contents of the ZIP file. That way you can see what subdirectories it will create, that is, if it is going to unpack into a single directory or make a mess. The JUnit ZIP file is very well behaved in this respect.


image

Figure 13.1 The JUnit home page



image

Figure 13.2 The SourceForge download site


Create a directory and unpack the JUnit ZIP file in there:


$ mkdir ~/junit

$ mv junit3.8.1.zip !$

$ cd !$

$ unzip junit3.8.1.zip


This warning from the installation instructions is worth noting:



IMPORTANT

Don’t install the junit.jar into the extention directory of your JDK installation. If you do so the test class on the filesystem will not be found.

image


The JDK installation directory has a subdirectory named jre/lib/ext. Don’t put the JUnit JAR file in there. If you have followed our instructions, you’re OK, since we had you create a new directory.

To use JUnit, the junit.jar file needs to be in your classpath. For example:


$ export CLASSPATH="${CLASSPATH}:${HOME}/junit/junit3.8.1/junit.jar"


That’s all the installing there is. It doesn’t feel like much, because you haven’t done much. All it provides is a JAR file that you will use when you want to run tests. That’s where it gets interesting.