The Purpose of Mocking

后端 未结 8 470
独厮守ぢ
独厮守ぢ 2020-12-29 15:33

What is the purpose of mocking?

I have been following some ASP.NET MVC tutorials that use NUnit for testing and Moq for mocking. I am a little unclear about the mock

8条回答
  •  渐次进展
    2020-12-29 16:11

    "Mock" is a heavily overloaded term in testing & TDD circles. See Martin Fowler's article Mocks Aren't Stubs. A "proper" mock knows what values it's supposed to receive and lets you know when it doesn't get what was intended; this allows you to do interaction testing instead of state testing - you verify that the class under test is passing the correct messages to its collaborators, in the correct sequence. Interaction testing is quite different from conventional state testing and can be hard to get your head around. Keeping in mind that interaction testing is the point of mocks may make them easier to understand.

提交回复
热议问题