locked
what is shims/stub/fakes in unit test RRS feed

  • Question

  • please describe with example that what is shims/stub/fakes ?

    what is a usage of shims/stub/fakes ?

    • Moved by Fei Hu Friday, December 1, 2017 1:55 AM
    Thursday, November 30, 2017 7:23 PM

Answers

  • please describe with example that what is shims/stub/fakes ?

    what is a usage of shims/stub/fakes ?

    https://www.telerik.com/products/mocking/unit-testing.aspx

    <copied>

    Mocking is a process used in unit testing when the unit being tested has external dependencies. The purpose of mocking is to focus on the code being tested and not on the behavior or state of external dependencies. In mocking, the dependencies are replaced by closely controlled replacements objects that simulate the behavior of the real ones. There are three main types of replacement objects - stubs, fakes and mocks.

    <end>

    https://www.developerhandbook.com/unit-testing/writing-unit-tests-with-nunit-and-moq/

    Thursday, November 30, 2017 8:52 PM
  • Fakes come in two flavors:

    • 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.

    Here is the MSDN doc which gives the specific info of it:

    https://msdn.microsoft.com/en-us/library/hh549175.aspx

     

    Regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Friday, December 1, 2017 3:08 AM
    • Marked as answer by Sudip_inn Thursday, December 7, 2017 12:33 PM
    Friday, December 1, 2017 3:08 AM

All replies

  • please describe with example that what is shims/stub/fakes ?

    what is a usage of shims/stub/fakes ?

    https://www.telerik.com/products/mocking/unit-testing.aspx

    <copied>

    Mocking is a process used in unit testing when the unit being tested has external dependencies. The purpose of mocking is to focus on the code being tested and not on the behavior or state of external dependencies. In mocking, the dependencies are replaced by closely controlled replacements objects that simulate the behavior of the real ones. There are three main types of replacement objects - stubs, fakes and mocks.

    <end>

    https://www.developerhandbook.com/unit-testing/writing-unit-tests-with-nunit-and-moq/

    Thursday, November 30, 2017 8:52 PM
  • Hello Sudip_inn,

    The issue is more related to unit test, I will move the thread to Visual Studio unit testing forum for suitable support.

    If you have some grammar or code errors in using C#, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 1, 2017 1:55 AM
  • Fakes come in two flavors:

    • 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.

    Here is the MSDN doc which gives the specific info of it:

    https://msdn.microsoft.com/en-us/library/hh549175.aspx

     

    Regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Friday, December 1, 2017 3:08 AM
    • Marked as answer by Sudip_inn Thursday, December 7, 2017 12:33 PM
    Friday, December 1, 2017 3:08 AM
  • can you please explain stub and shim with example code mean how they look like with code.
    Thursday, December 7, 2017 12:34 PM