mocking 101

10

Click here to load reader

Upload: buildmaster

Post on 27-Jun-2015

2.210 views

Category:

Technology


3 download

DESCRIPTION

Slides from the wellington Dot net user group mocking talk on 2nd April 2008

TRANSCRIPT

Page 1: Mocking 101

A brief introduction to test doubles and mocking frameworks

Page 2: Mocking 101

Unit testing goals

Verification Feedback Speed Focus Isolation

Page 3: Mocking 101

Test Doubles

4 types of test doubleDummy – We just pass it round and don’t do

anything with itFake – Working implementations but take

shortcutsStubs – Canned answers to expected callsMocks – Pre programmed with responses

and expectations that certain calls should be made

Page 4: Mocking 101

Why? Feedback cycle needs to be as small as

possible to be useful We need to remove pain points from

being necessaryDatabase callsUIThird party libraries

We can remove reliance on the rest of the code being complete before knowing the current unit works

Page 5: Mocking 101

Mocking frameworks

Provide a repeatable way to set up mocks/stubs/fakes with little code cost.

Test logic can stay within test We can develop as we test and get

immediate results (TDD)

Page 6: Mocking 101

Rhino.Mocks One of the most mature and feature

complete mocking frameworks Uses castle remoting to mock calls

Not able to mock static or sealed calls Fast Record/Replay Syntax Lots of help and code examples

available Open Source

Page 7: Mocking 101

Typemock Isolator

Mature and fully featured Uses IL Generation

Can mock static classes and callsCan chain events

Commercial licence available for full feature set and support

Main commercial mocking framework so features ++

Page 8: Mocking 101

Moq

New Kid on the block .net 3.5 only No record/replay semantics, just

expectations Less code clutter to tests Not feature complete In active development Open source

Page 9: Mocking 101

How?

It’s time to code

Page 10: Mocking 101

Links

Rhino Mocks: http://www.ayende.com/projects/rhino-mocks.aspx

Typemock: http://www.typemock.com/ Moq: http://code.google.com/p/moq Me: http://www.bgeek.net

[email protected]://www.twitter.com/buildmaster