1. Stubs, Shims, and Mocks, oh my!
Unit Testing with Visual Studio Fakes
Consulting/Training
2. Consulting/Training
About Me
Microsoft Client Development MVP
ASPInsider
Twitter: @joelcochran
Email: joelcochran@gmail.com
Blog: joelcochran.com
Lead Developer, WintellectNOW
3. Consulting/Training
About Wintellect
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops
to help our customers achieve their goals through advanced software-based consulting and training solutions.
consulting
Wintellect helps you build better software, faster,
tackling the tough projects and solving the software
and technology questions that help you transform
your business.
Architecture, Analysis and Design
Full lifecycle software development
Debugging and Performance tuning
Database design and development
training
Wintellect's courses are written and taught by some of
the biggest and most respected names in the Microsoft
programming industry.
Learn from the best. Access the same training
Microsoft’s developers enjoy
Real world knowledge and solutions on both current
and cutting edge technologies
Flexibility in training options – onsite, virtual, on
demand
who we are
4. Wintellect’s On-Demand Video Training Solution
Try it free
Code: <INSERT CODE HERE> WintellectNOW.com
COCHRAN-13
Authors Enjoy:
Royalty Income
Personal Branding
Cross-Sell Opps
Free library access
Subscribers Enjoy:
Expert Instructors
Quality Content
Practical Application
All Devices
Consulting/Training Individuals | Businesses | Enterprise Organizations
5. What are Microsoft (Visual Studio) Fakes?
A tool for generating code entry and isolation endpoints
Generates “fake” assemblies and includes them in your project
Fakes then contain Stub and Shim classes
Included with Visual Studio 2012 and 2013 [requires Ultimate]
Consulting/Training
6. Consulting/Training
Stubs
Easily create Mock objects based on Interfaces
Encourages good design
Often requires refactoring
8. Consulting/Training
Shims
Used for more difficult test items
Or when you cannot refactor
Shims are considered evil
Use sparingly
Refactor as soon as possible
Remove Shims
10. Consulting/Training
Configuration
Editing the Config files
Allows you to minimize generated code
Enabling Diagnostics
Don’t forget to turn on Diagnostics in VS Options
12. Consulting/Training
Additional Resources
Testing un-testable code:
http://channel9.msdn.com/Events/TechEd/Europe/2012/DEV411
Isolating Code Under Test with Microsoft Fakes:
http://msdn.microsoft.com/en-us/library/hh549175(v=vs.110).aspx
Peter Provost’s blog (search for Fakes):
http://www.peterprovost.org/blog/