One example could be you have an Service like below..
interface IService
{
void Save(int itemValue);
}
If I have some business logic that ends up calling Save on the IService above, a particular test may not care that it was called. You may only have to have the interface stubbed out so you can execute your business logic.
Given the following "business logic"
public int BusinessMethod(IService svc)
{
int a = 1 + 1 + 1;
svc.Save(a);
return a;
}
The following test shows that we don't care to "verify" the save method was called, however it did have to create the mock to begin with.
[Test]
public void test()
{
var mockService = new Mock<IService>()
var returnedVal = BusinessMethod(mockService.Object);
Assert.AreEqual(returnedVal, 3);
}
The above test doesn't care that the "Save" method was called with 3, it only cares that it returned 3...
Hope this helps.
Jason
Brad, I'm really green to Moq in particular and mocking in general.
Would you please be more specific for newbies like myself. A few examples would help me understand your kind reply.
This seems so strange to me. If I choose not to "observe" which I guess means "verify" then how will I know whether my test worked?
Is it not the act of observation/verification that causes a red/green result?