mock objects presentation

Post on 10-May-2015

1.021 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Mock Objects and Mock Frameworks

Andriy Buday

Weather Service Example

It is still raining in Lviv So how to test sunny weather?

Introduction…

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

A mock object must have 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 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

Why use mock objects?

Promote interface-based design Refine interfaces Test unusual, unlikely and exceptional

situations

When to use Mock Objects?

Non-deterministic or random behaviour Difficult setup Behavior hard to cause Slow real objects UIs Test needs to make queries not supported

by real object Non-existent real objects

Diff Between Mocks and Stubs

Dummyare not really used

Fakehave working implementation but not real

Stubspass prepared answers

Mocksprovide expectation logic

Warehouse Example

Regular tests Nmock Rhino Mocks Paskal Mock

Rhino Mocks

Dynamic mocks1. on concrete class

2. mock some methods

Partial mocks1. on class/interface

2. every member should be mocks

3. compiler default for not expected methods called

Strict mocks1. similar to partial

2. test fail if not expected method was called

Rhino can kill

weather

dilemma

easily

Questions?

top related