首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 软件时空 > 软件相关 > Mock Objects
【标  题】:Mock Objects
【关键字】:Mock,Objects
【来  源】:http://blog.csdn.net/swverification/archive/2006/12/27/1465120.aspx

Mock Objects

What are Mock Objects

§Any dummy object that stands in for a real object that is not available, or is difficult to use in a test case

§(More rigid): A mock object must have the ability to set up expectations and provide a self-validation mechanism

Why use Mock Objects?

§Help keep design decoupled

§Check code’s usage of another object

§Test code from the inside out

§Make tests run faster

§Make it easier to write code for problematic resources

§Defer having to write a class

§Test components in isolation from the rest of the system

§Promote interface-based design

§Encourage composition over inheritance

§Refine interfaces

§Test unusual, unlikely, and exceptional situations

When to use Mock Objects

§Non-deterministic or random behavior

§Difficult setup

§Behavior hard to cause

§Slow real objects

§UIs

§Test needs to make queries not supported by real object

§Non-existent real objects

How to use Mock Objects

§Create them by hand from scratch

§Create them by hand, using the MockObjects library

§Use MockMaker to generate the mock object prior to execution

§Use EasyMock to generate the mock object at runtime

By hand from scratch

§Create a class that implements the same interface as the real one

§Hard code return values

§Lots of work to create and validate expectations

By hand with MockObjects library

§Create the mocks

§Set state/expectations

§Execute code

§Have mocks verify expectations

§Lots of duplication across Mocks

MockMaker

§Given an interface or class, create a mock object for it

§Mock can then be tweaked

EasyMock

§Create mock object at runtime

§Two modes: record and replay

EasyMock adjustments

§Make the following adjustments to EasyMock example code in the book:

§EasyMock.niceControlFor should be MockControl.createControl

§control.activate should be control.replay

 

EasyMock Matcher

§Easymock by default uses Object.equals() type comparison

§For arrays, this doesn’t look at content

§Solution: the first time you call a method that takes an array as a parameter, set the matcher before setting return value

 

 

如何区别软件的好坏:【上一篇】
Intel多核培训感想:【下一篇】
【相关文章】
  • mock object 的使用
  • 比较Business Objects与MicroStrategy的10个关键性问题
  • 可变类和不可变类(Mutable and Immutable Objects)
  • Building Browser Helper Objects with Visual Studio 2005
  • DirectShow帮助文档学习笔记之DirectShow Objects
  • EasyMock 2 使用指南
  • sysobjects
  • Beyond Single Language——有感Beginning C# Objects中文版
  • 使用EasyMock来进行测试
  • 移:Naked Objects
  • 【随机文章】
  • windowsxp密码
  • 天堂2 上班族V兽人准暴君
  • sarg抓的图片
  • [转贴]100个Linux最佳站点
  • CISSP安全认证升级
  • 什么是数码单反?
  • Bison 笔记三
  • 路由器网络接口解析大全(一)
  • QQ经典小技巧四则:拒绝广告短信的无端骚扰
  • C#目录遍历
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.