Post on 11-May-2015
description
A MOCKERY OF A PRESENTATION
Gil ZilberfeldTypemock
Typemock
™
Who am I?
Software developer for 15 years
Technical Evangelist at Typemock
@gil_zilberfeld
Let me tell you about my first REAL job...
Typemock
™
What’s the plan?
The isolation problem
Hand rolling
The tools you can use
Start now
o It's not that hard
Typemock
™
Why do we need isolation?
Applications are complex
We can’t touch a live system
When we call the database
Setup
Teardown
Repeat
Typemock
™
And then…
When tests run slowly
You stop running tests
You stop writing tests
Typemock
™
Really…
Typemock
™
What do I need?
A mock?A stub?A fake?A test double?
Typemock
™
Mocks aren't stubs!
Typemock
™
Modern Tests
AAAArrangeActAssert
Typemock
™
AAA DEMO
Typemock
™
Mocks vs. stubs don't matter in AAA world, so let's use fake
Typemock
™
Fakes help me change behavior without changing the code
Typemock
™
Fakes help me verify calls
Typemock
™
Roll your own fakes
• Derive from an interface
• Override virtual methods
• Inject it
MVC DEMO
Typemock
™
41%
Typemock
™
Isolation (not mocking) Frameworks
• Focus on the code under test, not the other way around
• APIs for changing behavior and verification
ISOLATION FRAMEWORKS DEMO
Typemock
™
What are the differences?
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
Typemock
™
My name is Gil and I was an idiot
(I'm better now)
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
Typemock
™
Start now
It's a productivity tool
Make it part of your tool belt
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/
Typemock
™
Questions?