Mocks,stubs,Shims differences RRS feed

  • Question

  • Can someone list out the differences between a mock,stubs,shims?? I just started unit testing.
    Saturday, May 17, 2014 7:32 PM


  • Hi Sobin,

    Thank you for posting in the MSDN forum.

    KeesDijk shared us some information about the “Stubs” and “Mocks”.

    Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.

    Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.



    About the stubs and shims:

    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.



    In addition, other case about the similar issue:


    Best Regards,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 19, 2014 9:28 AM