Getting Started with JUnit
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.
JUnit is a simple framework that supports automated testing in Java.
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.
Here is some of the documentation that comes with 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.
Confirm that you have a complete installation by comparing the contents of your junit3.8.1 directory to the expected contents.
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.
First, change into the junit3.8.1 directory. Then...
java junit.textui.TestRunner junit.samples.AllTests
java junit.awtui.TestRunner junit.samples.AllTests
java junit.swingui.TestRunner junit.samples.AllTests
Here are answers to common problems students encounter when installing JUnit by hand. Let me know if you have any other questions.
A complete junit3.8.1/ directory contains:
|README.html||a superset of this file, with fewer details|
|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|
|doc||documentation and useful articles|
The junit directory contains two subdirectories:
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.