Smalltalk balloon

Getting Started with JUnit


CS 2530
Intermediate Computing



I have adapted this help sheet from the README file that comes with JUnit 3.8.1, both to simplify it and to fill in some details that you may find helpful. Let me know you have any questions.



Introduction

JUnit is a simple framework that supports automated testing in Java.



Setting Up JUnit

JUnit is a Java package containing all the code needed to create and run automated tests. It is usually distributed as a .jar file.

Running JUnit with Dr. Java. Dr. Java comes with JUnit installed as a part of its basic set-up. If you are using Dr. Java for the course, then you are all set!

Running JUnit without an IDE. If you do most of your Java programming at the command line, then you might want to download JUnit and install it on your system. See these helpful instructions below.



Documentation

Here is some of the documentation that comes with JUnit:



Downloading and Installing JUnit

You can download JUnit from my site (v3.8.1) or from www.junit.org. The result is a zip file named junit.zip.

To install JUnit, do the following.

  1. Unzip the junit.zip file. Place it in the directory of your choice.

    Confirm that you have a complete installation by comparing the contents of your junit3.8.1 directory to the expected contents.


  2. Add junit.jar to your CLASSPATH.

    How to do this is system-specific. Here are some instructions that we have learned from experience on some particular platforms.

    If you use a different system or have any problems setting your classpath using these instructions, please let me know.


  3. Test your installation by using one of JUnit's interfaces to run the suite of tests that comes with JUnit. All of the tests should pass.

    First, change into the junit3.8.1 directory. Then...

Here are answers to common problems students encounter when installing JUnit by hand. Let me know if you have any other questions.



Full Contents of the Release

A complete junit3.8.1/ directory contains:

README.html a superset of this file, with fewer details
cpl-v10.html JUnit's license
junit.jar a jar file with the JUnit framework and tools
src.jar a jar file with the source code of the junit framework
junit the source code of the JUnit samples
javadoc javadoc-generated documentation
doc documentation and useful articles

The junit directory contains two subdirectories:



Common Problems

Don't place junit.jar into the extension directory of your JDK installation. If you do, your system will not be able to find the test classes.

The reason that you have to switch into the junit3.8.1 directory to run the tests is that JUnit's test suite is not in the junit.jar file. If you add INSTALL_DIR/junit3.8.1/ to your classpath, you should be able to run the tests from any directory, as well as access the sample classes that come with JUnit from anywhere, too.



Eugene Wallingford ..... wallingf@cs.uni.edu ..... September 21, 2012