Moles in Visual Studio 2012 – The new Fake feature
Unit testing is not easy. One of the greatest challenges is to identify external dependencies and provide mock objects and behaviors. Few years ago Microsoft Research came out with an infrastructure called “moles” designed to solve this problem. With moles is was extremely easy to inject mock behavior and functionality to existing code (including code we don’t own such as the .net framework itself)
Well In Visual Studio 2012 moles was adopted and introduced as the “Fake” feature.
Now all we need to do to inject mock behavior to external code is create a fake assembly by right clicking the referenced assembly and choosing “Add Fake Assembly”. Now all left to do is to inject mock behavior to the new mock objects and use it in our test.
The details about using the fake objects and injecting mock functionality can be found here.