免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1105 | 回复: 0
打印 上一主题 下一主题

easy testing using easymock [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-23 09:34 |只看该作者 |倒序浏览
        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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP