When to Expect and When to Stub?

前端 未结 3 850
旧时难觅i
旧时难觅i 2020-12-29 09:31

I use NMock2, and I\'ve drafted the following NMock classes to represent some common mock framework concepts:

  • Expect: this specifies what a mock

3条回答
  •  旧巷少年郎
    2020-12-29 10:04

    "Expect actions, stub queries". If the call should change the state of the world outside the object under test, then make it an expectation--you care about how it gets called. If it's just a query, you can call it once or six times without changing the state of the system, then stub the call.

    One more thing, notice that the distinction is between stubs and expectations, that is individual calls, not necessarily entire objects.

提交回复
热议问题