1. import and create your test class

import the JUnit classes so you can use them in your code.

import junit.framework.TestCase;

public class StudentTest
    extends TestCase {

  // code goes here...
}

2. define your fixtures

fixtures are objects that are used in your test cases.

define your fixtures as private instance variables.

initialize your fixture in the setUp() method

setUp() is called before each call to each test case.

...
public class StudentTest
    extends TestCase {

  private Student aStudent;     // fixture to be used for testing

  public void setUp() {
    aStudent = new Student("Joe", "888-2993");  // initialize it here
  }
}

3. use fixtures in your test cases

fixture objects created in setUp are new objects in each test case.

the two test cases on the right run succesfully

...
  public void testSetName() {
    assertEquals(aStudent.getName(), "Joe");

    aStudent.setName("Manuel");
    assertEquals(aStudent.getName(), "Manuel");
  }

  public void testSomethingElse() {
    // aStudent .. is new here
    assertEquals(aStudent.getName(), "Joe");
    assertEquals(aStudent.getID(), "888-2993");
  }

}

References and Notes

  1. JUnit.org has more information on how to use the package.
  2. Documentation for the asserts in JUnit http://www.junit.org/apidocs/org/junit/Assert.html