What is Mocking?

前端 未结 8 1128
遥遥无期
遥遥无期 2020-11-22 03:15

What is Mocking?                                                                                                    .

8条回答
  •  不思量自难忘°
    2020-11-22 04:09

    There are plenty of answers on SO and good posts on the web about mocking. One place that you might want to start looking is the post by Martin Fowler Mocks Aren't Stubs where he discusses a lot of the ideas of mocking.

    In one paragraph - Mocking is one particlar technique to allow testing of a unit of code with out being reliant upon dependencies. In general, what differentiates mocking from other methods is that mock objects used to replace code dependencies will allow expectations to be set - a mock object will know how it is meant to be called by your code and how to respond.


    Your original question mentioned TypeMock, so I've left my answer to that below:

    TypeMock is the name of a commercial mocking framework.

    It offers all the features of the free mocking frameworks like RhinoMocks and Moq, plus some more powerful options.

    Whether or not you need TypeMock is highly debatable - you can do most mocking you would ever want with free mocking libraries, and many argue that the abilities offered by TypeMock will often lead you away from well encapsulated design.

    As another answer stated 'TypeMocking' is not actually a defined concept, but could be taken to mean the type of mocking that TypeMock offers, using the CLR profiler to intercept .Net calls at runtime, giving much greater ability to fake objects (not requirements such as needing interfaces or virtual methods).

提交回复
热议问题