/** *

* TestPerson uses the TrivialTestFramework to see whether * the Person class does what it should. *

* This is an example of what "testing" really means * in programming circles: explicitly checking if functions * do what they're supposed to. *

* The really cool kids write the tests *first* along with stubs for the * code to test, make sure the tests all fail, then fill in the stubs with * code that passes the tests. *

* * @version 1.0, Feb 7 2007 * @author Jim Mahoney */ public class TestPerson { public static TrivialTestEngine tests = new TrivialTestEngine(); public static void main(String args[]){ print("-- test Person class --"); Person john = new Person("John Smith"); tests.ok(john instanceof Person, "new Person(name) returns a Person"); tests.ok(john.getPhone() == "phone?", "getPhone() for him is 'phone?'"); tests.ok(john.getName() == "John Smith", "getName() does the right thing"); john.setPhone("111 2222"); tests.ok(john.getPhone() == "111 2222", "setPhone and getPhone both work"); Person sally = new Person(); tests.ok(sally.getName() == "anonymous", "new Person(); getName() gives 'anonymous'"); tests.ok(Person.getNumberOfPeople() == 2, "Person.getNumberOfPeople()"); print(tests.getReport()); } // Save some typing. public static void print(String s){ System.out.println(s); } }