Normally, stubs and dependency injection are used to intercept and return results specified by the unit test, to prevent code external to the targeted method from returning unpredictable results that may skew test results. Fakes provides dependency isolation through means of instrumenting targeted code with detoured calls to delegates specified by the test, and automatically creating stubs from interfaces.
Fakes framework does not remove the need for appropriate use of stubs, nor an excuse for poor architecture. However, Fakes are extremely useful when working with legacy code that is not properly built for unit testing.
The Moles Isolation Framework has been productized and released as "Fakes", packaged with Visual Studio 2012 Ultimate. The syntax and concepts are practically identical, with some minor differences. I will comb through these pages, and provide Fakes syntax, to supplement the Moles. Ironically, PEX did not make it into production as a hands-on code explorations tool. PEX is the product from which Moles was spun.
If you have additional questions, please post them to www.StackOverflow.com. I keep an eye on questions posted with the Moles tag.
Fakes Famework Shims and Stubs
Moles and PEX
- What is Pex and Moles?
These are previous introductory posts to Pex and Moles:
- CodeRush Templates for Pex and Moles
- What are "Moles assemblies"?
- Why doesn't the .Moles assembly appear in Solution Explorer?
- What are .MOLES files?
- What is a Call Detour?
- How Do I Write a Detour?
- How Do I Detour a Stub/Mole Type Constructor?
- How To Detour a Static Constructor
- How Moles Detours Work?
- What are Mole and Stub types?
- When Do I Use a Stub or Mole Type?
- How To guides
- How to I Mole an Assembly?
- How do I make my test use Moles?
- How do I make my build and/or test servers use Pex and Moles?
- How to Mole a Specific Type Instance
- How do I Mole .NET Framework Types?
- How To Mole the System Assembly
- Moles Error Says I Haven't Instrumented a Type. What Does That Mean?
- "Moles requires tests to be IN an instrumented process"
- "Assembly not available in the currently targeted framework"
- Why Are Moles Assemblies Still Added To My Project?
Steps to properly remove Moles from a project.
(More coming about Pex!)