CS 201 - Lab 2

Testing with JUnit

In this lab you will practice using JUnit to test Java classes.

Getting started

Import lab2.zip.  (File->Import...->General->Existing Projects into Workspace->Archive File).  You should see a project called lab2 in the Package Explorer.

Your Task

Your task is to write JUnit tests to test the Date class, which represents a calendar date.  You should add your tests to the DateTest class.  The class already contains one test object (accessed using the aDate field) and several test methods.

Your goal is to find TWO bugs in the Date class.

The Date class supports the following methods:

Leap years

The rule for leap years is:

If a year is evenly divisble by 4, and either

- it is NOT evenly divisible by 100, OR

- it IS evenly divisible by 400

then it is a leap year.

Examples:

2007 is NOT a leap year (not divisible by 4)

2008 is a leap year (divisible by 4, and not divisible by 100)

1900 is NOT a leap year (divisible by 100 and not divisble by 400)

2000 is a leap year (divisible by 400)