// ------------------------------------------------------------------------- /** * This class provides a basic set of test cases for the * {@link Student} class. * * @author Stephen Edwards * @version Feb 22, 2005 */ public class StudentTest extends junit.framework.TestCase { //~ Instance/static variables ............................................. private Student fred; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new StudentTest object. */ public StudentTest() { // Usually, nothing goes here for a test case class, since // all fields should be initialized in setUp() instead. } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Sets up the test fixture. * Called automatically before every test case method. * * A "test fixture" is a fixed set of objects that start in a * predetermined, known state, and that serve as the "starting point" * for executing all the test cases in one test class. Typically, a * test fixture is stored as class fields in a test class, and is * initialized in this {@link #setUp()} method. */ protected void setUp() { fred = new Student( "fred" ); } // ---------------------------------------------------------- /** * Tears down the test fixture. * Called automatically after every test case method. * * This method is used to "clean up" any resources that were allocated * or tied up in {@link #setUp()}. Often, it is completely empty and * can be omitted. Here, it is provided for completeness. */ protected void tearDown() { // Nothing to do, in this example } // ---------------------------------------------------------- /** * A simple test case that shows a basic assertion, testing the * {@link Student#name()} accessor. */ public void testName() { assertEquals( "fred", fred.name() ); } // ---------------------------------------------------------- /** * Another example test case, testing that the number of assignments * on a fresh {@link Student} object is indeed zero. */ public void testNoAssignments() { assertEquals( 0, fred.numAssignments() ); } // ---------------------------------------------------------- /** * Test computing the assignment average when there are no assignments. */ public void testNoAssignmentAverage() { assertEquals( 0, fred.assignmentAverage() ); } }