MOCK OBJECTS WOULDNT IT BE NICE?

Wouldn't it be nice

if the mock could be told what method calls to expect from the object(s) being tested? Then you could test the object behavior from the other side as well: not just the response to a call (i.e., the return value and state change), but also what methods in the mock were called from the class being developed.

Wouldn't it be nice

if the mock could be told what value(s) to return from those calls? That would let you verify more complex interactions.

Wouldn't it be nice

if it could be told to return different values each time a method is called? Again, this would let you test even more complex interactions.

Wouldn't it be nice

if you could ask it to verify that everything that was expected to happen did, indeed, happen, and to throw an exception if any expectation was violated? Some conditions could be detected immediately (such as a method being called too many times, or with the wrong arguments), but some (such as a method not being called enough times) couldn't until the mock was asked to check what really happened against what was expected.

Wouldn't it be nice

if the mock threw an Exception as soon as it knew it was being used in a way that wasn't desired? That would report the failure as close to the point of failure as possible, making it easier and faster to find and fix the problem.

Wouldn't it be nice

if you had tools that made this easy and painless?

Wouldn't it be nice

if you could do all that? Well, (as you might have guessed), you can indeed do all of that with the tools we'll be talking about in the remainder of this chapter.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值