You are the lead tester for Contoso, Ltd. The company is using Microsoft Visual Studio to develop a new software product.
Management wants to test the product as it is developed. Some components that require testing have dependencies that are not yet built or are otherwise unavailable.
You need to test the components.
In the table below, identify where only a shim or a stub can be used in the situation. Make only one selection in each column.
Hot Area:
Correct Answer:
Explanation/Reference:
* Interfaces and abstract methods. Stubs provide implementations of interfaces and abstract methods that can be used in testing. Shims can’t instrument interfaces and abstract methods, because they don’t have method bodies.
* Internal types. Both stubs and shims can be used with internal types that are made accessible by using the assembly attribute InternalsVisibleToAttribute.
In general, we recommend that you use stub types to isolate from dependencies within your codebase.
* Private methods. Shims can replace calls to private methods if all the types on the method signature are visible. Stubs can only replace visible methods.
Note:
* A stub replaces a class with a small substitute that implements the same interface. To use stubs, you have to design your application so that each component depends only on interfaces, and not on other components. (By "component" we mean a class or group of classes that are designed and updated together and typically contained in an assembly.)
* 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. Shims can be used to replace calls to assemblies that you cannot modify, such .NET assemblies.
Reference: Visual Studio, Isolating Code Under Test with Microsoft Fakes