Home » Articles, Knowledge

Isolating Code under Test with Microsoft Fakes

26 September 2012 No Comment

This article explains how Microsoft Fakes perform a similar role than mocking in unit testing, helping you to isolate the code you are testing in Visual Studio by replacing other parts of the application with stubs or shims. A stub replaces another class with a small substitute that implements the same interface. A shim modifies the compiled code of your application at run time so that instead of making a specified method call, it runs the shim code that your test provides.

You should normally use stubs for calls within your Visual Studio solution and shims for calls to other referenced assemblies. There are also other aspects and contexts to consider like performance; Static methods, sealed types; private methods; interfaces and abstract methods. It is generally recommended touse stub types to isolate from dependencies within your codebase. You can do this by hiding the components behind interfaces. Shim types can be used to isolate from third-party components that do not provide a testable API. The article provides also some “getting started” tips for both stubs and shims, followed by two deeper “how to” sections for each of these concepts. Finally, a section is devoted to discussing options and issues in Fakes code generation and compilation, and describing the naming conventions for Fakes generated types, members, and parameters.

Related Content:

Comments:

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

*