Unit Testing Your Classes

You have created several classes in the previous two labs. Below are the names of these classes:

When unit testing, developers often create a main() method in the class for the purpose of testing.
  1. Create a main() method in each of the classes you have developed.
  2. Instantiate an object of each class in its respective main() method.
  3. Use System.out.println() and print each object.
To run the main() method of the class in Eclipse, you will need to bring the class into focus in the editor and click Run. To run the class from the command-line, create the test directory in the same directory as your src directory if it doesn't exist. Then compile and run each class separately from the test directory as shown below for the Fraction class.

javac -d . ../src/lab3/Fraction.java
java lab3.Fraction

You will notice that in the classes where you haven't implemented the toString() method, the objects are represented in a way you might not have expected. This is the default implementation of the toString() method in Java. You may use the toString() methods in the code below for the Rectangle and Point classes. Code for each of the classes follows for those that were not able to complete the previous labs.