标题: easy testing using easymock [打印本页] 作者: wangsong2 时间: 2006-03-23 09:34 标题: easy testing using easymock to test the collaborating Classes, we used to use the mock objects, but it's really boring to write many mock objects, so the easymock can do this for me. to use the easymock, you have to :
1: create the control for the collaborating interface
2: get the mock object from the control
3: record the hebavior of the mock
4: replay it
5: test the classes
6: verify
some to note here is: the collaborating class must implements some interface, and mock object create from interface(Using dynamic proxy in j2sdk).
example code:
control = MockControl.createControl(Collaborator.class); // 1
mock = (Collaborator) control.getMock(); // 2
classUnderTest = new ClassUnderTest();
classUnderTest.addListener(mock);
// 3 (we do not expect anything)
control.replay(); // 4
control.verify(); //5