One of the problems we encountered in unit test is: if the tested component (class or project) is a, component A depends on Component B, therefore, when testing a in unit test atest of component A, it also depends on B. After B is changed, the test result of A may be affected. To isolate the impact of B on a during test A, this is the problem Microsoft fakes should solve.
To solve the problem above, Microsoft fakes replaces component B with stubs or shims.
See: http://msdn.microsoft.com/library/vstudio/hh549175
Stub uses the following method: Replace the dependent class with a class that implements the same interface. The premise for using this method is that a depends on B, which must be an "interface" instead of a specific class, so that it is possible to create a stub that implements interface B.
Shim adopts the following methods:
So in general, use stubs for cballs within your Visual Studio solution, and Shims for cballs to other referenced assemblies.
Use stubs
See: http://msdn.microsoft.com/en-us/library/vstudio/hh549174
The main points of this article are:
You need to add a reference to a in atest -- atest is used to test a. Of course, you need to add a reference to;
You need to add the B reference on which a depends in atest -- this is because you need to create stubs for B.
At the same time, B may also depend on other components. You also need to add references to other components in atest; otherwise, the atest still cannot run normally.
Right-click B's reference and choose add fakes assembly"
In the test code, create a stub instance and provide implementation methods.
Use Microsoft fakes isolation test code