posted 21 years ago
Usually with mock objects you create an interface that has the same method calls as your original object that you are testing. Then you have both your mock object and your original object implement the same interface. Then you have your program use this interface instead of your real object. This allows you to switch out the real object and the mock object without your program knowing objects have been switched out.
Car implements ICar
MockCar implements ICar
ICar car = new MockCar();
//The code below wouldn't know if 'car' is a mock or not.
This is usually how mock objects are used. (At least in our shop) This leaves out the ability to test static methods. Does anyone else have another method that might be more elegant?
[ May 08, 2003: Message edited by: Dale DeMott ]
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)