import the JUnit classes so you can use them in your code.
import junit.framework.TestCase; public class StudentTest extends TestCase { // code goes here... }
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 } }
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"); } }