25
A MOCKERY OF A PRESENTATION Gil Zilberfeld Typemock

A Mockery of a persentation

Embed Size (px)

DESCRIPTION

A presentation on mocking and isolation frameworks in the .net space.

Citation preview

Page 1: A Mockery of a persentation

A MOCKERY OF A PRESENTATION

Gil ZilberfeldTypemock

Page 2: A Mockery of a persentation

Typemock

Who am I?

Software developer for 15 years

Technical Evangelist at Typemock

@gil_zilberfeld

Let me tell you about my first REAL job...

Page 3: A Mockery of a persentation

Typemock

What’s the plan?

The isolation problem

Hand rolling  

The tools you can use

Start now

o It's not that hard

Page 4: A Mockery of a persentation

Typemock

Why do we need isolation?

Applications are complex

We can’t touch a live system

When we call the database

Setup

Teardown

Repeat

Page 5: A Mockery of a persentation

Typemock

And then…

When tests run slowly

You stop running tests

You stop writing tests

Page 6: A Mockery of a persentation

Typemock

 Really…

Page 7: A Mockery of a persentation

Typemock

What do I need?

A mock?A stub?A fake?A test double?

Page 8: A Mockery of a persentation

Typemock

Mocks aren't stubs!

Page 9: A Mockery of a persentation

Typemock

Modern Tests

AAAArrangeActAssert

Page 10: A Mockery of a persentation

Typemock

AAA DEMO

Page 11: A Mockery of a persentation

Typemock

Mocks vs. stubs don't matter in AAA world, so let's use fake

 

Page 12: A Mockery of a persentation

Typemock

Fakes help me change behavior without changing the code 

Page 13: A Mockery of a persentation

Typemock

Fakes help me verify calls

 

Page 14: A Mockery of a persentation

Typemock

Roll your own fakes

• Derive from an interface

• Override virtual methods

• Inject it

Page 15: A Mockery of a persentation

MVC DEMO

 

Page 16: A Mockery of a persentation

Typemock

41%

Page 17: A Mockery of a persentation

Typemock

Isolation (not mocking) Frameworks   

• Focus on the code under test, not the other way around

• APIs for changing behavior and verification

Page 18: A Mockery of a persentation

ISOLATION FRAMEWORKS DEMO

Page 19: A Mockery of a persentation

Typemock

What are the differences?

Page 20: A Mockery of a persentation

Typemock

My name is Gil andI did not use a framework

I used hand rolled fakesuntil it became complicated and I stopped unit testing

I knew about isolation frameworks, read about them, but thought they were too complicated

Page 21: A Mockery of a persentation

Typemock

My name is Gil and I was an idiot

(I'm better now)

Page 22: A Mockery of a persentation

Typemock

Unit tests are the antidote to stupid bugs

it's impossible to stick with unit testing without fakes

It's a waste of time using hand rolled mocks

Page 23: A Mockery of a persentation

Typemock

Start now

It's a productivity tool

Make it part of your tool belt

Page 24: A Mockery of a persentation

Typemock

Resources Typemock Blog

http://www.typemock.blog Mock Comparison Project

http://code.google.com/p/mocking-frameworks-compare/

Twitter: @gil_zilberfeld This week in testing:

http://www.typemock.com/this-week-in-test/

Page 25: A Mockery of a persentation

Typemock

Questions?