Thursday, December 06, 2012

Microsoft "Fakes" Testing Framework, Stub vs Shim

Isolating Code under Test with Microsoft Fakes

Fakes come in two flavors:

  • A stub replaces another 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.) (replacing methods that you could override)

  • 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. (non virtual methods, that you can not override)
  • No comments: