Mock Objects

In a typical JUnit test, some data is set up that is passed to the code under test,
and the return value is verified. All this does is test data — or state.

Mock objects allow the classes surrounding the class under to test to be
replaced with fake or mock versions. This allows a class to be tested in isolation
from its dependencies.

如上描述JUnit测试的是状态,Mock Objects测试的是同其他类的交互

Mock Objects 是对类或接口的伪造实现,通常用来mock被测试类的依赖环境(empty shells),他们比较简单所以不许要再被测试

 

The Mock Objects Library contains the following parts:

1. An expectation library to help define the expectations when creating
mock objects


2. Alternative APIs for many of the common JDK and J2EE libraries,
including network sockets, I/O, JDBC, Servlets, JMS, JNDI, and Java-
Mail. These alternative APIs extend the conventional APIs to include
clean interface separations from implementations, which allows code
that depends on these interfaces to be passed mock implementations —
as well as any other custom implementation — as needed.


3. Mock implementations for the APIs mentioned previously


4. A library for dynamically creating mocks at runtime from your unit
tests without having to define extra classes. This uses dynamic proxies.

The Mock Objects Library 通过CGLib的动态代理实现mock功能


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值