Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
Mock Objects: a Unit Test Story
By Taswar Bhatti
Taswar Bhatti
Blog: http://taswar.zeytinsoft.com
Twitter: taswarbhatti
eMail: taswar@zeytinsoft.com
What is a Mock Object?
A mock object is generally used as a stand-in, or replacement, for a real object while the system is being unit tested
(Proxy Pattern)
Joe the coder:
"I always thought Unit Testing sounded great but in reality its hard because we use databases, web services, COM and libraries which we don't have access to the code"
"We got real issues with dependencies man!!!!"
How am I suppose to write a unit test?????
oh me, oh my? What a lot of unit test go by?
Really? I mean seriously really???
Next thing you gonna tell me its
better than sliced bread
Mocking Framework in .Net
- Rhino Mocks
- FakeItEasy
- Typemock Isolator (Commercial)
- Nmock
- Telerik Justmock (Commercial)
- Moq
Well it helps eliminate a lot of code in unit testing, you will not have to code manual stubs or fakes.
Soon you will realize its not the Unit Test; but rather the design of the code that matters
Ok are you gonna show some code or what?
Demo
Downside of some mocking framwork
- Some cannot test sealed, private and protected classes and methods
- Learning curve
Things to watchout
- Unreadable test code
- Verifying the wrong thing
- Having more than one mock per test
- Overspecifying the tests
Suggested Readings
- Art of Unit Testing (Roy Osherove)
- Working Effectively with Legacy Code (Michael Feathers)
- Growing Object-Oriented Software, Guided by Tests (Steve Freeman & Nat Pryce)
Email: taswar@zeytinsoft.com
Blog: http://taswar.zeytinsoft.com
Twitter: taswarbhatti
Today is gone. Today was fun.
Tomorrow is another one.
Every day,
from here to there,
mock objects are everywhere.
Mocking Framework to the Rescue.
is it?