CpSc 461, Software Engineering Techniques

Unit Testing Exercise

In this exercise, you will have a chance to implement some unit tests using the JUnit unit testing framework.

To begin, download the following to your local machine:

Unzip the JUnit package and place BinaryTree.java, BinaryTreeTest.java, and junit.jar in the same directory. Compile the test suite with
C:\> javac -classpath .:junit.jar BinaryTreeTest.java
If the test suite compiled correctly, you should now have three .class files: BinaryTree.class, BinaryTree$Node.class, and BinaryTreeTest.class. Now start the JUnit GUI with
C:\> java -cp .:junit.jar junit.swingui.TestRunner
Click the button labeled "..." to select the BinaryTreeTest class, then click "Ok". To run the test suite, click "Run". Make sure that the "Reload classes every run" option is selected so that JUnit will pick up new versions of the test suite as you make changes and recompile.

There is a bug in BinaryTree.java. Add new unit tests to BinaryTreeTest.java until you find it. Visit the Getting Started page to learn more about JUnit.