Stub, Fakes and Mocks have different meanings across different sources. I suggest you to introduce your team internal terms and agree upon their meaning.
I think it is important to distinguish between two approaches: - behaviour validation (implies behaviour substitution) - end-state validation (implies behaviour emulation)
Consider email sending in case of error. When doing behaviour validation - you check that method Send
of IEmailSender
was executed once. And you need to emulate return result of this method, return Id of the sent message. So you say: "I expect that Send
will be called. And I will just return dummy (or random) Id for any call". This is behaviour validation:
emailSender.Expect(es=>es.Send(anyThing)).Return((subject,body) => "dummyId")
When doing state validation you will need to create TestEmailSender
that implements IEmailSender
. And implement Send
method - by saving input to some data structure that will be used for future state verification like array of some objects SentEmails
and then it tests you will check that SentEmails
contains expected email. This is state validation:
Assert.AreEqual(1, emailSender.SentEmails.Count)
From my readings I understood that Behaviour validation usually called Mocks. And State validation usually called Stubs or Fakes.