- 论坛徽章:
- 0
|
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
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4241/showart_89528.html |
|